Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type.IsEnum Property in Portable Class Library

I'm trying to code in a Portable Class Library using ASP.NET Core 1.0, the following instruction:

public static void WriteMessage<T>(T value)
{
    if (typeof(T).IsEnum)
    {
        Debug.Print("Is enum")
    }
    else
    {
        Debug.Print("Not Is enum")
    }
}

But this code does not compile because the compiler says that the property IsEnum is non present on Type.

Any suggestions?

like image 399
Karlok Avatar asked Jul 12 '16 11:07

Karlok


1 Answers

Some functionality from Type was moved to TypeInfo in .NET Core.

typeof(T).GetTypeInfo().IsEnum
like image 93
Gabriel Negut Avatar answered Oct 19 '22 08:10

Gabriel Negut