如何检查.NET Core中的类型是否抽象? [英] How to check if a type is abstract in .NET Core?

查看:91
本文介绍了如何检查.NET Core中的类型是否抽象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此代码在.NET(4.6及更低版本)中正常工作

This code works fine in .NET (4.6 and prior)

var types = typeof(SomeType).GetTypeInfo().Assembly.GetTypes()
from type in types
where !type.IsAbstract

,但在.NET Core(DNX Core 5.0)中,它会产生编译错误:

but in .NET Core (DNX Core 5.0) it is producing a compile error:


错误CS1061'类型'不包含的定义为'IsAbstract',找不到扩展方法'IsAbstract'接受类型为'Type'的第一个参数(您是否缺少using指令或程序集引用?)

Error CS1061 'Type' does not contain a definition for 'IsAbstract' and no extension method 'IsAbstract' accepting a first argument of type 'Type' could be found (are you missing a using directive or an assembly reference?)

那么如何在.NET Framework 4.6中检查类型在DNX Core 5.0中是否为抽象类型

推荐答案

我正在发布评论之一作为答案,因为这就是我要的:

I am posting one of the comments as an answer since it is what I was asking for:

type.GetTypeInfo().IsAbstract

这篇关于如何检查.NET Core中的类型是否抽象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆