Testing a generic parameter for enum type information
generic <class TValue>
...MyMethod()
{
// Testing a generic parameter for enum type information
System::Type^ enumType = TValue::typeid;
// Only enum types supported
if (!enumType->IsEnum)
{
throw gcnew System::ArgumentException("...");
}
// Only 32 bit integer enum types are supported
if (System::Enum::GetUnderlyingType(enumType) != System::Int32::typeid)
{
throw gcnew System::ArgumentException("...");
}
// [Flags] type enums not supported
array<System::Object^>^ attributes = enumType->
GetCustomAttributes(System::FlagsAttribute::typeid, false);
if (attributes->Length != 0)
{
throw gcnew System::ArgumentException("...");
}
}
No comments:
Post a Comment