【发布时间】:2014-03-20 14:28:57
【问题描述】:
如何测试一个类型的属性以查看它是否是指定类型?
编辑:我的目标是检查程序集以查看该程序集中的任何类型是否包含 MyType(或从 MyType 继承)的属性。
这是我走过的路……
AssemblyName n = new AssemblyName();
n.CodeBase = "file://" + dllName;
Assembly a = AppDomain.CurrentDomain.Load(n);
foreach (Type t in a.GetTypes())
foreach (PropertyInfo pi in t.GetProperties())
if ( pi.PropertyType is MyType ) // warning CS0184
Console.WriteLine("Found a property that is MyType");
编译时会出现警告 CS0184: The given expression never of the provided ('MyType') type
【问题讨论】:
标签: c# .net reflection