我想遍历联系人属性并将包含“数字”一词的属性添加到具有该值的列表中,我尝试使用反射但它不起作用。
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);
}
}
}
}