Invoking methods with optional parameters through reflection

According to MSDN, to use the default parameter you should pass Type.Missing.

If your constructor has three optional arguments then instead of passing an empty object array you’d pass a three element object array where each element’s value is Type.Missing, e.g.

type.GetParameterlessConstructor()
    .Invoke(BindingFlags.OptionalParamBinding | 
            BindingFlags.InvokeMethod | 
            BindingFlags.CreateInstance, 
            null, 
            new object[] { Type.Missing, Type.Missing, Type.Missing }, 
            CultureInfo.InvariantCulture);

Leave a Comment