2016-02-16 26 views
9

这个代码在.NET罚款(4.6和以前)如何在.NET Core中检查类型是否抽象?

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

但在.NET核心(DNX核5.0),它是产生编译错误:

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中的抽象类型是否为抽象类型?

enter image description here

+14

'type.GetTypeInfo()IsAbstract' –

+0

@LucasTrzesniewski正是我寻找!添加它作为答案。 –

+3

这不会是一个很好的答案TBH,我希望这是一个重复的 –

回答

1

我张贴的评论的,因为它的答案之一是我问了:

type.GetTypeInfo().IsAbstract 
相关问题