Given this example, an extension method which uses the name of the type to return a value from a dictionary by it's type using generic T.
public static T GetItem<T>(this Dictionary<string, object> dictionary)
{
var y = nameof(T);
var z = dictionary.FirstOrDefault(x => x.Key == y);
return (T)z.Value;
}
And used as
var item = dictionary.GetItem<SomeClass>();
Is it possible to get the nameof(T)
in the extension method above without providing any further parameters to the method? This appears to returns T
instead of the expected SomeClass
at runtime.