I have a class with a static factory method on it. I want to call the factory to retrieve an instance of the class, and then do additional initialization, preferablly via c#
+1 on "No".
Here's an alternative to the anonymous object way:
var instance = MyClass.FactoryCreate( SomeProperty => "Some value", OtherProperty => "Other value");
In this case FactoryCreate() would be something like:
FactoryCreate()
public static MyClass FactoryCreate(params Func[] initializers) { var result = new MyClass(); foreach (var init in initializers) { var name = init.Method.GetParameters()[0].Name; var value = init(null); typeof(MyClass) .GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.IgnoreCase) .SetValue(result, value, null); } return result; }