How to check if a type is abstract in .NET Core?

此生再无相见时 提交于 2019-12-10 12:41:04

问题


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

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

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

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?)

So how can I check if a type is abstract in DNX Core 5.0 the way I do it in .NET Framework 4.6?


回答1:


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

type.GetTypeInfo().IsAbstract


来源:https://stackoverflow.com/questions/35439749/how-to-check-if-a-type-is-abstract-in-net-core

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!