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
Try this:- (Use PropertyInfo )
Assembly myAss = Assembly.LoadFile(@"YourAssemblyPath.dll");
Type myType = myAss.GetType("MyNamespace.Demo1.STClass");
PropertyInfo myProp = myType.GetProperty("prpAssm");
Console.WriteLine(myProp.PropertyType);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.