我如何通过反射C#获取属性数据类型中的一类 [英] How do I get data type of property in a class through Reflection C#
本文介绍了我如何通过反射C#获取属性数据类型中的一类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为命名空间 MyNamespace.Demo1
,一个叫静态类 STClass
和类调用里面一个属性 prpAssm
。如何获得的数据类型的属性 prpAssm
?
解决方案
键入classType所= typeof运算(STClass);
的PropertyInfo的PropertyInfo = classType.GetProperty(prpAssm);
类型属性类型= propertyInfo.PropertyType;
如果类是在另一个项目中,你应该加载程序集。
VAR总成= Assembly.LoadFrom(@MyNamespace.Demo1.dll);
型classType所= assembly.GetType(MyNamespace.Demo1.STClass);
的PropertyInfo的PropertyInfo = classType.GetProperty(prpAssm);
类型属性类型= propertyInfo.PropertyType;
BR
I have a namespace called MyNamespace.Demo1
, one static class called STClass
and one property inside that class called prpAssm
. How do I get the data-type of property prpAssm
?
解决方案
Type classType = typeof(STClass);
PropertyInfo propertyInfo = classType.GetProperty("prpAssm");
Type propertyType = propertyInfo.PropertyType;
if the class is in another project you should load the assembly.
var assembly = Assembly.LoadFrom(@"MyNamespace.Demo1.dll");
Type classType = assembly.GetType("MyNamespace.Demo1.STClass");
PropertyInfo propertyInfo = classType.GetProperty("prpAssm");
Type propertyType = propertyInfo.PropertyType;
BR
这篇关于我如何通过反射C#获取属性数据类型中的一类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文