예제 #1
0
        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);
        }
예제 #2
0
        private Type[] getTypesFromCallingContext(InvokeMemberBinder binder)
        {
            // FIXME: avoid access to private members

            // +ICSharpInvokeOrInvokeMemberBinder.CallingContext
            var  cache = binder.GetFieldValue("Cache", true) as Dictionary <Type, object>;
            Type type  = cache?.FirstOrDefault().Key;

            return(type?.GetMethod("Invoke")?
                   .GetParameters()
                   .Skip(2)          // service args
                   .Select(t => t.ParameterType)
                   .ToArray());
        }