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