17

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?

Rahul Nikate
  • 6,192
  • 5
  • 42
  • 54
Karlok
  • 171
  • 1
  • 5
  • [documentation](https://msdn.microsoft.com/en-us/library/system.type.isenum(v=vs.100).aspx) says : "If the current Type represents a type parameter in the definition of a generic type or generic method, this property always returns false." [this](https://social.msdn.microsoft.com/Forums/en-US/7e805189-a7e5-4562-a6e4-ae9feff77da7/what-is-the-equivalent-of-fieldtypeisenum-in-metro?forum=winappswithcsharp) may be relevant, too – Cee McSharpface Jul 12 '16 at 11:27

1 Answers1

42

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

typeof(T).GetTypeInfo().IsEnum
Gabriel Negut
  • 13,860
  • 4
  • 38
  • 45