public void TestInvokeCtorViaConstructorInfo() { RunWith(type => { ConstructorInfo ctorInfo = type.Constructor(typeof(string), typeof(int)); object person = ctorInfo.CreateInstance(null, 10).WrapIfValueType(); VerifyFields(person, new { name = (string)null, age = 10 }); }); }
public static object CreateInstanceSafe(this ConstructorInfo ctor) { try { return(ctor.CreateInstance()); } catch (TargetInvocationException) { return(null); } }