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

1

10

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

Putrescine answered 16/2, 2016 at 17:55 Comment(4)
type.GetTypeInfo().IsAbstractMoquette
@LucasTrzesniewski Exactly what I am looking for! Add it as an answer.Putrescine
That wouldn't be a very good answer TBH, and I expect this to be a duplicateMoquette
I think it would be good to add this as an answer (even a self answer), just to make it easier for people to see. Particularly as this post has quite a few votes.Illusive
P
2

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

type.GetTypeInfo().IsAbstract
Putrescine answered 28/11, 2017 at 11:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.