Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How check if type is class?

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?

like image 425
Jean Carlos Avatar asked Aug 26 '16 18:08

Jean Carlos


3 Answers

Try calling GetTypeInfo() to get at this information.

like image 78
Daniel A. White Avatar answered Oct 07 '22 12:10

Daniel A. White


This is ok, on: .net Core 1.1

using System.Reflection;
bool isClass = obj.GetType().GetTypeInfo().IsClass;
like image 34
Zane Avatar answered Oct 07 '22 14:10

Zane


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;
like image 37
Rui Santos Avatar answered Oct 07 '22 13:10

Rui Santos