我如何测试类型的属性以查看它是否是指定的类型?
编辑:我的目标是检查程序集,以查看该程序集中的任何类型是否包含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");
Run Code Online (Sandbox Code Playgroud)
这会编译警告CS0184:给定的表达式永远不是提供的('MyType')类型