The simplest way I have found is to force the compiler’s hand by adding a cast to object
.
return (T)(object)i.Value;
More Related Contents:
- How can I cast int to enum?
- Get int value from enum in C#
- Create Generic method constraining T to an Enum
- Generics and casting – cannot cast inherited class to base class
- Value of type ‘T’ cannot be converted to
- implicit operator using interfaces
- How can I cast int to enum in C#?
- How do I cast int to enum in C#?
- Why enums require an explicit cast to int type?
- Specifying generic collection type param at runtime [duplicate]
- Generics: casting and value types, why is this illegal?
- Parse string to enum type
- Why can’t I cast from a List to List?
- .NET Casting Generic List
- Casting array to IEnumerable
- How to capture value OOPS & Generic [closed]
- How to loop through all enum values in C#? [duplicate]
- Generic Method Executed with a runtime type [duplicate]
- Null or default comparison of generic argument in C#
- c# covariant return types utilizing generics
- Passing a single item as IEnumerable
- Converting a generic list to a CSV string
- How to Compare Flags in C#?
- C# Get Generic Type Name
- How do I have an enum bound combobox with custom string formatting for enum values?
- Can I Create a Dictionary of Generic Types?
- Practical advantage of generics vs interfaces
- C# Enums: Nullable or ‘Unknown’ Value?
- Entity Framework – how do I get the columns?
- How do generics get compiled by the JIT compiler?