سؤال

I'm currently trying to get just the contacts from an Items collection retrieved from Outlook. The problem is that my cast to ContactItem sometimes breaks because there are non-contact items in the list (like distribution lists). Because these are COM objects, I need to check if the property MessageClass equals IPM.Contact. I'm not familiar with COM objects, so I don't know how to do this. I've tried using the following:

if(comObject.GetType().GetProperty(MessageClass).GetValue(comObject).Equals("IPM.Contact"))
{
    contactitems.add((ContactItem)comObject)
}

However, this fails because it cannot find the property on the comobject.

هل كانت مفيدة؟

المحلول

I checked MSDN, and they suggest at http://msdn.microsoft.com/en-us/library/ms268994.aspx to use object is ContactItem to check if it's a ContactItem. I've tried this, and it works.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top