連絡先のプロパティを反復処理し、「Number」という単語を含むものを値のリストに追加したいのですが、リフレクションを使用しようとしましたが、機能しません。
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);
}
}
}
}