public override Object Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) { // Do they want us to process Default Values? if (parameters != null && parameters.Length > 0) { int length = parameters.Length; ParameterInfo[] p = null; for (int i = 0; i < length; i++) { // if the parameter is missing we need to get a default value. if (parameters[i] == Type.Missing) { if (p == null) { p = GetParameters(); // If the parameters and the number of parameters passed are // not the same then we need to exit. if (p.Length != length) { throw new ArgumentException(Environment.GetResourceString("Arg_ParmCnt"), "parameters"); } } if (p[i].DefaultValue == System.DBNull.Value) { throw new ArgumentException(Environment.GetResourceString("Arg_VarMissNull"), "parameters"); } parameters[i] = p[i].DefaultValue; } } // Check for attempt to create a delegate class, we demand unmanaged // code permission for this since it's hard to validate the target // address. if (RuntimeType.CanCastTo((RuntimeType)DeclaringType, (RuntimeType)typeof(Delegate))) { new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand(); } Object[] args = new Object[length]; for (int index = 0; index < length; index++) { args[index] = parameters[index]; } Object retValue = InternalInvoke(invokeAttr, binder, args, culture, binder == Type.DefaultBinder); for (int index = 0; index < length; index++) { parameters[index] = args[index]; } return(retValue); } return(InternalInvoke(invokeAttr, binder, parameters, culture, binder == Type.DefaultBinder)); }