views:

386

answers:

2

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.

Sample code below

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

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);
        }
    }
}

}

A: 

Of cause it doesn't work - it's a COM object. You should use the properties from CDO space.

IgorM
+1  A: 

Try using MAPI CDO.

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

Here's some MAPI Blogs to help as well:

Paige Watson