Is not possible.
System.__COMObject
is a class declared as internal
and all its methods are exposed by System.Runtime.InteropServices.Marshal
. Therefore, this class is nothing more than a wrapper for the COM object, not having a type . Net derivative that can be obtained by the method Object.GetType()
.
If you want to see more about this class, I recommend taking a look at the source code:
Editing:
According to your comment, what you want then is to get RTTI from the COM library. C# does not allow this type of direct interaction with RTTI of unmanageable objects, so what to do?
1. What language your COM library was written in. It’s usually C++, but it can be written in Object Pascal as well, for example.
2. Was the COM library compiled with RTTI? If not, there is nothing that can be done but cry for the library developers to compile it with RTTI. Why? Because without RTTI, there is simply no way to re-flect an object.
3. Build a library in the same language as your COM library that does the Reflection for you. Using P/Invoke you interact with it within C#. Note that you will never have an object of the type System.Type
, because this object only exists in manageable codes, which is not the case for your COM library.
Maybe just build a structure that encapsulates the std::type_info
returned by operator typeid
(if C++ is the language of the COM library, of course), and building the methods to get this value from your COM class is enough.
The RTTI analysis library is not complicated no (or does not seem to me at first), and needs only a few methods implemented according to your need. Compared to the other solutions I presented in the comments, it is a fraction of the complexity/effort, no doubt.
Do you know if there is another way to return the type of an object in the class
System.__COMObject
? with the second code it returned right, but in string form, and not Type, as I need..– Jovita
Create your own empty types then, and make a string map for your types. Problem half solved (Mcgyver would be proud).
– Oralista de Sistemas
I need the type, in the form of Type, to do the Reflection, I create a string map with the types does not help, understood?
– Jovita
+1 by Mcgyver! It would be necessary to write an MSIL wrapper for each COM class used. This wrapper could be done in C# or MSIL. The two are as big a job as the amount of COM classes you handle and the complexity of the relationships between them. Both could be done in Runtime, including (the MSIL version is more appropriate in this case). What specific use do you want? There may be another approach to solving your bigger problem.
– Vinícius Gobbo A. de Oliveira
I get information from an object-shaped simulation of a program that I don’t have access to anything regarding code. This object is an instance of a class in the library of this program, which is not from the .NET. This object has several objects inside, and each object of this is different from the other, with some things in common, what I want is to take the name of the attributes of these various objects, for example, I have a valve-like object, in it I have a whole called pressure, and a float called temperature, I want to be able to print "pressure" and "temperature".
– Jovita
i managed to return the type using the method:
Microsoft.VisualBasic.Information.TypeName(Objeto)
However this method returns a string, to do the Reflection I need to return in the type System.Type.– Jovita
In this case there is a solution, but it depends on one thing: language that the COM library was written. I will edit my answer.
– Vinícius Gobbo A. de Oliveira
I got half q by forcing the Reflexion, I forgot to reply my post, I will do this, I had not seen his last comment nor the edition of the reply...
– Jovita
Thank you very much for your answers and your time!
– Jovita