如何在System.Type的在C#中返回一个系统.__ COMObject的类型
我在做一个节目,我想做一个反映,但对于这一点,我需要的类型类的一个对象,对不对?使用.GetProperties()方法...所以我tryed这一点:
I'm doing a program and I want to do a Reflection, but for this, I need an Object of the Type class, right? to use the .GetProperties() method... So I tryed this:
键入的typeName = simObjects.getType();
但.GetType()将返回系统.__ COMObject。这是不是有帮助。
同样的情况与.typeof()。我搜索和发现了另一个代码,这样一句:
But the .GetType() is returning "System.__COMObject". And this is not helpfull. The same happens with .typeof(). I search and found another code, this one:
键入的typeName =(类型)Microsoft.VisualBasic.Information.TypeName(simObjects);
但这种方法的System.Type返回一个字符串,我需要它,任何天才要比能帮帮我吗?
But this method return a String, and I need it in System.Type, Can any genious please help me?
嗯,我知道它的后期answear,前一段时间我解决我的问题,我会answear,希望它可以帮助别人。
Well, i know its a late answear, i solve my problem some time ago, i'll answear, hope it can help someone.
我如我所愿,但它的工作很细没有使用反射。
I did not use reflextion as i wish, but its working pretty fine.
foreach(PropertyDescriptor descrip in TypeDescriptor.GetProperties(COMObject))
{
if(descrip.Name == "Attribute Name")
{
foreach(PropertyDescriptor descrip2 in TypeDescriptor.GetProperties(descrip))
{
if(descrip2.Name == "sub attribute Name")
{
}
}
}
}
这代码返回属性的名称,例如,假设我COMObject有这样的属性:
This code return the name of the attributes, for example, imagine that my COMObject have this attributes:
int age;
string name;
Son Phill;
和儿子有:
int age;
string name;
在第一循环中,descrip.Name将是年龄,名称和菲尔,并在第二个(supose该condiiton回报与真正的儿子),时代和名。
in the first loop, the descrip.Name will be "age", "name" and "Phill", and in the second (supose that the condiiton return true with "Son"), "age" and "name".
希望这可以帮助别人。