[英]How do I get data type of property in a class through Reflection C#
我有一個名為命名空間MyNamespace.Demo1
,一個叫靜態類STClass
和類調用內部一個屬性prpAssm
。 如何獲取屬性prpAssm
的數據類型?
Type classType = typeof(STClass);
PropertyInfo propertyInfo = classType.GetProperty("prpAssm");
Type propertyType = propertyInfo.PropertyType;
如果該類在另一個項目中,則應加載程序集。
var assembly = Assembly.LoadFrom(@"MyNamespace.Demo1.dll");
Type classType = assembly.GetType("MyNamespace.Demo1.STClass");
PropertyInfo propertyInfo = classType.GetProperty("prpAssm");
Type propertyType = propertyInfo.PropertyType;
BR
試試這個:-(使用PropertyInfo )
Assembly myAss = Assembly.LoadFile(@"YourAssemblyPath.dll");
Type myType = myAss.GetType("MyNamespace.Demo1.STClass");
PropertyInfo myProp = myType.GetProperty("prpAssm");
Console.WriteLine(myProp.PropertyType);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.