Tôi đang cố gắng để mã trong một Portable Class Library
sử dụng ASP.NET Core 1.0
, các hướng dẫn sau đây:Type.IsEnum về tài sản trong di Class Library
public static void WriteMessage<T>(T value)
{
if (typeof(T).IsEnum)
{
Debug.Print("Is enum")
}
else
{
Debug.Print("Not Is enum")
}
}
Tuy nhiên, mã này không biên dịch bởi vì trình biên dịch nói rằng tài sản IsEnum
là phi có trên Loại.
Mọi đề xuất?
[tài liệu] (https://msdn.microsoft.com/en-us/library/system.type.isenum (v = vs.100) .aspx) nói: "Nếu Kiểu hiện tại thể hiện một tham số kiểu trong định nghĩa của một kiểu generic hoặc phương thức generic, thì thuộc tính này luôn trả về 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) có thể có liên quan, quá – dlatikay