You should be able to just use Convert.ChangeType()
instead of your custom code:
public T Get<T>(Stats type) where T : IConvertible
{
return (T) Convert.ChangeType(PlayerStats[type], typeof(T));
}
More Related Contents:
- How to capture value OOPS & Generic [closed]
- Nullable type as a generic parameter possible?
- Generic constraint to match numeric types [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
- Static Generic Class as Dictionary
- Converting a generic list to a CSV string
- Using IsAssignableFrom with ‘open’ generic types
- Sorting an IList in C#
- c# compare two generic values [duplicate]
- Accessing a property of derived class from the base class in C#
- Get all types implementing specific open generic type
- Parse string to enum type
- Why does this generic constraint compile when it seems to have a circular reference
- Calling generic method with Type variable [duplicate]
- Case insensitive access for generic dictionary
- What does new() mean?
- Ambiguous call between two C# extension generic methods one where T:class and other where T:struct
- How do I tell if a type is a “simple” type? i.e. holds a single value
- Entity Framework – how do I get the columns?
- How can I write a generic anonymous method?
- Filtering out values from a C# Generic Dictionary
- How do generics get compiled by the JIT compiler?
- How to convert c# generic list to json using json.net?
- Build c# Generic Type definition at runtime
- Hashtable to Dictionary syncroot .
- Initializing a Generic variable from a C# Type Variable
- Generic Web Api controller to support any model