来自Discovering derived types using reflection的代码:
public static List<Type> FindAllDerivedTypes<T>(Assembly assembly) { var derivedType = typeof(T); return assembly .GetTypes() .Where(t => t != derivedType && derivedType.IsAssignableFrom(t) ).ToList(); }
你这个怎么用的啊!!
public interface ITest { void aa(); } public class Testa:ITest { #region ITest 成员 public void aa() { throw new NotImplementedException(); } #endregion } public class Testb:ITest { #region ITest 成员 public void aa() { throw new NotImplementedException(); } #endregion } var list = FindAllDerivedTypes<code.ITest>(typeof(code.ITest).Assembly); dudu站长威武
用反射技术!!
能详细点吗
@拖鞋王子:
例子:
Type t = Type.GetType("System.IO.Stream");
Console.WriteLine(t.BaseType);
@田麦成: 还有问题么??
public class A { } public class B : A { } public class C : B { }
[括号里填写你要查找的类名]
Type t = typof(B);
Console.WriteLine(t.BaseType);
这样就可以返回一层基类了