c# - Casting generic COM object to a specific .NET class -


i'm not c# programmer excuse me if it's silly question, can't find solutions.

i have object. it's com object , tostring() returns "system.__comobject". when examining inner contents debugger can see object has property called object , it's instance of actual class want. however, object class has no property object, , when i'm trying cast object desired type exception. how should com object converted .net object?

if know type you'd be, set method convert yourself, using dynamic access properties:

public static myobject convertfromcomobject(dynamic comobject) {     return comobject.object; } // or, if doesn't work: public static myobject convertfromcomobject(dynamic comobject) {     return new myobject { myproperty = comobject.object.myproperty }; } // or maybe public static myobject convertfromcomobject(dynamic comobject) {     return new myobject { myproperty = comobject.myproperty }; } 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -