Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET: How do I determine if an object is a COM object?

Tags:

.net

com

How do I determine if an object is a COM object? I need to call Marshal.FinalReleaseComObject on all COM objects in an array of type Object.

like image 305
Jonathan Allen Avatar asked Feb 26 '10 20:02

Jonathan Allen


People also ask

How do you check if an object is a specific type C#?

To determine whether an object is a specific type, you can use your language's type comparison keyword or construct. For example, you can use the TypeOf… Is construct in Visual Basic or the is keyword in C#. The GetType method is inherited by all types that derive from Object.

How do you check if an object is a specific type?

You can check object type in Java by using the instanceof keyword. Determining object type is important if you're processing a collection such as an array that contains more than one type of object. For example, you might have an array with string and integer representations of numbers.

How to check object type in vb net?

In VB.NET, you need to use the GetType method to retrieve the type of an instance of an object, and the GetType() operator to retrieve the type of another known type. Once you have the two types, you can simply compare them using the Is operator.


3 Answers

Marshal.IsComObject

like image 129
David Morton Avatar answered Sep 28 '22 18:09

David Morton


typeof(myObject).IsCOMObject

or

instanceOfMyObject.GetType().IsCOMObject
like image 24
Yuriy Faktorovich Avatar answered Sep 28 '22 18:09

Yuriy Faktorovich


You can call GetType() and inspect the IsCOMObject property

like image 41
Nick Avatar answered Sep 28 '22 17:09

Nick