It is very difficult to use anonymous types using the ...<T>() method. The main way to do this includes an example of hacking, i.e.
var dummy = new { X = 13, Y = 7 }; Foo(dummy);
or more succinctly:
Foo(new { X = 13, Y = 7 });
which uses generic type inference to output T here of an anonymous type. Foo<T>(T obj) can be your actual method or it can be a method that in turn calls GetInsertString<TDto>() , i.e.
Perhaps you can also combine the two:
private static string GetInsertString<TDto>(TDto example = null) { .. your code .. }
and give an example only when necessary.
However, the βby exampleβ approach is fragile and susceptible to cracking. I highly recommend you simply define POCO:
public class MyType { public int X {get;set;} public int Y {get;set;} }
and use GetInsertString<MyType> .
source share