遍历使用Outlook联系人的属性遍历、属性、联系人、Outlook

2023-09-03 08:17:12 作者:逃出世间炼狱

我要遍历联系人的属性,并添加那些包含单词号码与值列表,我尝试使用反射,但它不工作。

I want to iterate through a contacts properties and add those that contain the word "Number" to a list with the value, i tries using reflection but it doesnt work.

样品$ C $以下

使用系统; System.Collections中使用; 使用System.Collections.Generic; 使用的System.Reflection; 使用Microsoft.Office.Interop.Outlook;

using System; using System.Collections; using System.Collections.Generic; using System.Reflection; using Microsoft.Office.Interop.Outlook;

命名空间DuplicateNumbers {     公共类的ContactService     {         公共ContactItem联系{获得;私定; }

namespace DuplicateNumbers { public class ContactService { public ContactItem Contact { get; private set; }

    private IDictionary<string,string> phoneNumbers = new Dictionary<string, string>();

    public ContactService(ContactItem contact)
    {
        Contact = contact;
    }

    public IDictionary<string,string> PhoneNumbers
    {
        get
        {
            if(phoneNumbers.Count == 0)
            {
                PopulatePhoneNumbers();
            }
            return phoneNumbers;
        }
    }

    private void PopulatePhoneNumbers()
    {
        _ContactItem ci = Contact as _ContactItem;
        MemberInfo[] members = ci.GetType().FindMembers(MemberTypes.All, BindingFlags.Instance, (m,criteria) => true, null);
        foreach (var info in members)
        {
            if(info.Name.Contains("Number"))
            {
                phoneNumbers.Add(info.Name,info.Value);
            }
            Console.WriteLine(info);
        }
    }
}

}

推荐答案

尝试使用MAPI CDO。

Try using MAPI CDO.

下面是一个可能让你开始了一个微软的网站:如何使用CDO阅读MAPI地址

Here's a microsoft site that might get you started: How to use CDO to read MAPI Addresses

下面是一些MAPI博客帮助和:

Here's some MAPI Blogs to help as well:

史蒂芬格里芬 马特·施特勒 Steven Griffin Matt Stehle
 
精彩推荐