如何从propertydescriptor获取类名? [英] How to get class name from propertydescriptor ?

查看:260
本文介绍了如何从propertydescriptor获取类名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有属性描述符集合,但我无法获得与属性相关的类名。任何人都可以分享我如何从propertydescriptor获取类名,我必须得到该类的属性信息?



谢谢和问候,

Amal



我是什么尝试过:



为了获得propertyinfo我试过的propertyinfo.GetType()。GetProperties(BindingFlags.Public | BindingFlags.Instance)



但是我无法获得确切的信息。当我尝试使用

类型t = TypeOf(ClassName);

PropertyInfo propertyInfo = t.GetProperties(BindingFlags.Public | BindingFlags.Instance);

i获得了所需的信息,但我必须在所需的位置提供类名。我必须动态获取classname以获取上面的propertyinfo。

解决方案

你可以试试

TypeDescriptor.GetClassName Method(Object,Boolean)(System.ComponentModel) [ ^ ]


使用ComponentType属性:

 SMThumbnailSet ts =  new  SMThumbnailSet( @  D:\ Temp \ NoThumbs); 
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(ts);
PropertyDescriptor prop = pdc.Find( MaxIndex);
类型t = prop.ComponentType;
Console.WriteLine(t.ToString());

将打印:

 SMUtilityClasses.SMThumbnailSet 


Hi All,

I have property-descriptor collection , but i couldn't get the class name in which the properties are related. Could anyone share me how to get the class name from the propertydescriptor which i have to get the propertyinfo of that class?

Thanks and Regards,
Amal

What I have tried:

In order to get the propertyinfo i tried by propertyDescriptor.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance)

but i could not get the exact information. When i try using the
Type t= TypeOf(ClassName);
PropertyInfo propertyInfo= t.GetProperties(BindingFlags.Public| BindingFlags.Instance);
i got the needed information, Yet i have to give the classname in the needed place. I have to get the classname dynamically here to get the propertyinfo as above.

解决方案

You could try
TypeDescriptor.GetClassName Method (Object, Boolean) (System.ComponentModel)[^]


Use the ComponentType property:

SMThumbnailSet ts = new SMThumbnailSet(@"D:\Temp\NoThumbs");
PropertyDescriptorCollection pdc = TypeDescriptor.GetProperties(ts);
PropertyDescriptor prop = pdc.Find("MaxIndex", false);
Type t = prop.ComponentType;
Console.WriteLine(t.ToString());

Will print:

SMUtilityClasses.SMThumbnailSet


这篇关于如何从propertydescriptor获取类名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆