简体   繁体   English

如何检查C#中COM对象的属性X是否具有值Y?

[英]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.

相关问题 使用 LINQ,其中一个 object 属性的值为 x,我如何在不同的属性中返回该值 - Using LINQ, where one object property has a value of x, how do I return the value in a different property 如何知道图表中点(X,Y)的X值,如何知道YC#的值? - How I can know X value of point (X, Y) in chart and I know the value of Y C#? 如何在反序列化中检查对象是否已更改属性C# - How to check if an object has changed property in deserialisation c# 当它具有ref参数时,如何从带有动态参数的C#中调用VB6 COM对象? - How do I call a VB6 COM object from C# with dynamic when it has a ref parameter? 如何检查COM dll是否在C#中注册 - How do I check if a COM dll is registered in C# c#如何检查队列是否包含具有特定值的对象属性? - c# how to check if queue contains object property with a specific value? 如何在c#中使用相同的属性名将值从类X复制到类Y? - How to copy value from class X to class Y with the same property name in c#? 调试时如何快速检查Array [x,y]的值? - How do i check the value of Array[x,y] quickly when debugging? 从C#启动时,为什么从VB调用C#COM对象时出现0x80070002错误? - Why do I get 0x80070002 error calling a C# COM object from VB when launched from C#? 如何检查匿名对象属性是否为空C# - How do I check if an anonymous object properties are not empty C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM