internal static Type GetCallingContext(this InvokeMemberBinder binder) { if (binder == null) { throw new ArgumentNullException(nameof(binder)); } // FIXME: avoid access to private members var cache = binder.GetFieldValue("Cache", true) as Dictionary <Type, object>; // .NET Core + .NET Framework Type type = cache?.FirstOrDefault().Key; if (type != null) { return(type); } if (binder.TryGetPropertyValue(out object context, "CallingContext", true) || // .NET Core binder.TryGetPropertyValue(out context, "Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder.CallingContext", true) || // .NET Framework binder.TryGetFieldValue(out context, "Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder.callingContext", true)) // Mono { return(context as Type); } throw new ArgumentException(UNS_MSG); }
internal static IEnumerable <CSharpArgumentInfo> GetArgInfo(this InvokeMemberBinder binder) { if (binder == null) { throw new ArgumentNullException(nameof(binder)); } // FIXME: avoid access to private members if (binder.TryGetFieldValue(out object info, "_argumentInfo", true) || // .NET Core binder.TryGetPropertyValue(out info, "Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder.ArgumentInfo", true) || // .NET Framework binder.TryGetFieldValue(out info, "Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder.argumentInfo", true)) // Mono { return(info as IEnumerable <CSharpArgumentInfo>); } throw new ArgumentException(UNS_MSG); }
internal static IEnumerable <Type> GetGenericArgTypes(this InvokeMemberBinder binder) { if (binder == null) { throw new ArgumentNullException(nameof(binder)); } // FIXME: avoid access to private members if (binder.TryGetPropertyValue(out object types, "TypeArguments", true) || // .NET Core binder.TryGetPropertyValue(out types, "Microsoft.CSharp.RuntimeBinder.ICSharpInvokeOrInvokeMemberBinder.TypeArguments", true) || // .NET Framework binder.TryGetFieldValue(out types, "Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder.typeArguments", true)) // Mono { return(types as IEnumerable <Type>); } throw new ArgumentException(UNS_MSG); }