[英]How do I check if Property X of a COM object has value Y in C#?
I'm currently trying to get just the contacts from an Items collection retrieved from Outlook. 我目前正在尝试仅从Outlook检索的Items集合中获取联系人。 The problem is that my cast to ContactItem sometimes breaks because there are non-contact items in the list (like distribution lists).
问题是我对ContactItem的转换有时会中断,因为列表中有非接触项(例如通讯组列表)。 Because these are COM objects, I need to check if the property
MessageClass
equals IPM.Contact
. 因为这些是COM对象,所以我需要检查属性
MessageClass
等于IPM.Contact
。 I'm not familiar with COM objects, so I don't know how to do this. 我不熟悉COM对象,所以我不知道该怎么做。 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. 但是,这失败了,因为它无法在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. 我检查了MSDN,他们建议在http://msdn.microsoft.com/zh-cn/library/ms268994.aspx上使用
object is ContactItem
来检查它是否为ContactItem。 I've tried this, and it works. 我已经尝试过了,而且有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.