After reviewing this blog by Kirill Osenkov (How to create a generic List of anonymous types?) I am trying to do something a little more advanced and having issues.
The following code compiles:
var anon = new { One = "1", Two = "2" };
var result = DoSomething(anon);
public static T DoSomething<T>(T value)
{
return value;
}
But if I try to add an additonal generic type, I cannot get it to build:
var anon = new { One = "1", Two = "2" };
var result = DoSomethingElse<int>(anon);
public static T2 DoSomethingElse<T, T2>(T value)
where T2 : new()
{
return new T2();
}
Since I have no way of specifiying that T is typeof(anon), I can't seem to get it to infer this when given a type for T2. Is this possible?