Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

enter image description here

like image 905
Nikolay Kostov Avatar asked Feb 16 '16 17:02

Nikolay Kostov


1 Answers

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

type.GetTypeInfo().IsAbstract
like image 197
Nikolay Kostov Avatar answered Oct 01 '22 06:10

Nikolay Kostov