Hello!
One way to do this is to create a general-purpose dynamic invocation helper:
Then, instead of
Good luck!
One way to do this is to create a general-purpose dynamic invocation helper:
// using System.Dynamic;// using System.Linq;// using Microsoft.CSharp.RuntimeBinder;publicstaticclass ObjectHelpers { privatestaticreadonly CSharpArgumentInfo argInfo = CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null); publicstaticobject DynamicInvoke(object target, object[] args) { var del = target as Delegate; if (del != null) return del.DynamicInvoke(args); var dynamicObject = target as DynamicObject; if (dynamicObject != null) { object result; var binder = Binder.Invoke(CSharpBinderFlags.None, null, Enumerable.Repeat(argInfo, args.Length)); if (dynamicObject.TryInvoke((InvokeBinder)binder, args, out result)) return result; } thrownew InvalidOperationException("Invocation failed"); } }
l(args)
, use ObjectHelpers.DynamicInvoke(l, args)
.Good luck!