Esempio n. 1
0
 protected override MethodInfo GetMethodImpl()
 {
     if (this._invocationCount != (IntPtr)0 && this._invocationList != null)
     {
         object[] objArray = this._invocationList as object[];
         if (objArray != null)
         {
             int index = (int)this._invocationCount - 1;
             return(((Delegate)objArray[index]).Method);
         }
         MulticastDelegate multicastDelegate = this._invocationList as MulticastDelegate;
         if (multicastDelegate != null)
         {
             return(multicastDelegate.GetMethodImpl());
         }
     }
     else if (this.IsUnmanagedFunctionPtr())
     {
         if (this._methodBase == null || !(this._methodBase is MethodInfo))
         {
             IRuntimeMethodInfo methodHandle = this.FindMethodHandle();
             RuntimeType        runtimeType  = RuntimeMethodHandle.GetDeclaringType(methodHandle);
             if (RuntimeTypeHandle.IsGenericTypeDefinition(runtimeType) || RuntimeTypeHandle.HasInstantiation(runtimeType))
             {
                 runtimeType = this.GetType() as RuntimeType;
             }
             this._methodBase = (object)(MethodInfo)RuntimeType.GetMethodBase(runtimeType, methodHandle);
         }
         return((MethodInfo)this._methodBase);
     }
     return(base.GetMethodImpl());
 }
 protected override MethodInfo GetMethodImpl()
 {
     if ((this._invocationCount != IntPtr.Zero) && (this._invocationList != null))
     {
         object[] objArray = this._invocationList as object[];
         if (objArray != null)
         {
             int index = ((int)this._invocationCount) - 1;
             return(((Delegate)objArray[index]).Method);
         }
         MulticastDelegate delegate2 = this._invocationList as MulticastDelegate;
         if (delegate2 != null)
         {
             return(delegate2.GetMethodImpl());
         }
     }
     return(base.GetMethodImpl());
 }
Esempio n. 3
0
        protected override MethodInfo GetMethodImpl()
        {
            if (_invocationCount != (IntPtr)0 && _invocationList != null)
            {
                // multicast case
                Object[] invocationList = _invocationList as Object[];
                if (invocationList != null)
                {
                    int index = (int)_invocationCount - 1;
                    return(((Delegate)invocationList[index]).Method);
                }
                MulticastDelegate innerDelegate = _invocationList as MulticastDelegate;
                if (innerDelegate != null)
                {
                    // must be a secure/wrapper delegate
                    return(innerDelegate.GetMethodImpl());
                }
            }
            else if (IsUnmanagedFunctionPtr())
            {
                // we handle unmanaged function pointers here because the generic ones (used for WinRT) would otherwise
                // be treated as open delegates by the base implementation, resulting in failure to get the MethodInfo
                if ((_methodBase == null) || !(_methodBase is MethodInfo))
                {
                    IRuntimeMethodInfo method        = FindMethodHandle();
                    RuntimeType        declaringType = RuntimeMethodHandle.GetDeclaringType(method);

                    // need a proper declaring type instance method on a generic type
                    if (RuntimeTypeHandle.IsGenericTypeDefinition(declaringType) || RuntimeTypeHandle.HasInstantiation(declaringType))
                    {
                        // we are returning the 'Invoke' method of this delegate so use this.GetType() for the exact type
                        RuntimeType reflectedType = GetType() as RuntimeType;
                        declaringType = reflectedType;
                    }
                    _methodBase = (MethodInfo)RuntimeType.GetMethodBase(declaringType, method);
                }
                return((MethodInfo)_methodBase);
            }

            // Otherwise, must be an inner delegate of a SecureDelegate of an open virtual method. In that case, call base implementation
            return(base.GetMethodImpl());
        }