共用方式為


Marshal.IsComObject(Object) 方法

定義

指示指定物件是否表示 COM 物件。

public:
 static bool IsComObject(System::Object ^ o);
public static bool IsComObject (object o);
static member IsComObject : obj -> bool
Public Shared Function IsComObject (o As Object) As Boolean

參數

o
Object

要檢查的物件。

傳回

如果 o 參數為 COM 類型,則為 true,否則為 false

例外狀況

onull

備註

IsComObjecttrue如果 實例的類別型別是使用 System.Runtime.InteropServices.ComImportAttribute 屬性化,或是其直接或間接衍生自使用 ComImportAttribute 屬性的類別,則傳回 。 Tlbimp.exe (型別程式庫匯入工具) 工具會在匯入型別程式庫時為您套用此屬性。

另外兩種方法也會判斷指定的物件是否代表 COM 物件,但傳回 true 的需求與此方法的需求不同。 Type.IsImporttrue如果類別 (或介面) 直接以 ComImportAttribute 屬性化,則會傳回 ;它不會針對衍生型別傳回 trueRegistrationServices.TypeRepresentsComTypetrue如果型別是使用 ComImportAttribute 或 衍生自具有相同 GUID 的型別,則會傳回 。

適用於

另請參閱