19

In .Net we have Type.IsClass to check if a type is a class using System.Reflection.

But in .Net Core no. So, how can I check?

2
  • 3
    Always I use google before, if you think this question is useful please give a negative vote, but not make useless comments. Aug 26, 2016 at 18:42
  • @MethodMan 100% disagree considering the subset of API in .net core 1.x Jun 28, 2017 at 21:55

3 Answers 3

23

Try calling GetTypeInfo() to get at this information.

0
10

This is ok, on: .net Core 1.1

using System.Reflection;
bool isClass = obj.GetType().GetTypeInfo().IsClass;
9

In .NET Core 2.2 you can do:

bool isClass = obj.GetType().IsClass;

The following will no longer work:

bool isClass = obj.GetTypeInfo().IsClass;
bool isClass = obj.GetType().GetTypeInfo().IsClass;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.