青岛正大集团,贪狼 棋子和松子,辣妈闺女似双胞胎
添加测试类:
public class testclass2 : testclass1 { } public class testclass1 : testclass0 { public override void testmethod() { } } public class testclass0 : itestinterface { public virtual void testmethod() { } } public interface itestinterface { }
1.判断是否实现了指定接口
//true
var hasinterface = typeof(testclass2).getinterfaces().any(i => i.name == nameof(itestinterface));
2.判断是否继承了指定基类
//true
var issuboftestclassbase = typeof(testclass2).issubclassof(typeof(testclass0));
3.判断是否重写了基类方法
获取指定方法的信息后,可以通过declaringtype-声明此方法的成员类信息,判断与当前类信息是否一致。
//false
var hastestclass2overridemethod = typeof(testclass2).getmethod(nameof(testclass0.testmethod)).declaringtype.equals(typeof(testclass2));
//true
var hastestclass1overridemethod = typeof(testclass1).getmethod(nameof(testclass0.testmethod)).declaringtype.equals(typeof(testclass1));
4.判断类a是否为类b的嵌套类
public class testclass { public class testnestedclass { } }
测试:
//true
var isnestedintestclass= typeof(testclass).getnestedtypes().any(i=>i.equals(typeof(testclass.testnestedclass)));
5. 类/接口的访问类型
通过如下访问类型的组合,进行判断
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论