public override ParameterInfo[] GetIndexParameters()
        {
            int length = 0;

            ParameterInfo[] parametersNoCopy = null;
            MethodInfo      getMethod        = this.GetGetMethod(true);

            if (getMethod != null)
            {
                parametersNoCopy = getMethod.GetParametersNoCopy();
                length           = parametersNoCopy.Length;
            }
            else
            {
                getMethod = this.GetSetMethod(true);
                if (getMethod != null)
                {
                    parametersNoCopy = getMethod.GetParametersNoCopy();
                    length           = parametersNoCopy.Length - 1;
                }
            }
            if ((parametersNoCopy != null) && (parametersNoCopy.Length == 0))
            {
                return(parametersNoCopy);
            }
            ParameterInfo[] infoArray2 = new ParameterInfo[length];
            for (int i = 0; i < length; i++)
            {
                infoArray2[i] = new ParameterInfo(parametersNoCopy[i], this);
            }
            return(infoArray2);
        }
 internal ParameterInfo[] GetIndexParametersNoCopy()
 {
     if (this.m_parameters == null)
     {
         int             length           = 0;
         ParameterInfo[] parametersNoCopy = null;
         MethodInfo      getMethod        = this.GetGetMethod(true);
         if (getMethod != null)
         {
             parametersNoCopy = getMethod.GetParametersNoCopy();
             length           = parametersNoCopy.Length;
         }
         else
         {
             getMethod = this.GetSetMethod(true);
             if (getMethod != null)
             {
                 parametersNoCopy = getMethod.GetParametersNoCopy();
                 length           = parametersNoCopy.Length - 1;
             }
         }
         ParameterInfo[] infoArray2 = new ParameterInfo[length];
         for (int i = 0; i < length; i++)
         {
             infoArray2[i] = new RuntimeParameterInfo((RuntimeParameterInfo)parametersNoCopy[i], this);
         }
         this.m_parameters = infoArray2;
     }
     return(this.m_parameters);
 }
 // Token: 0x06004774 RID: 18292 RVA: 0x0010290C File Offset: 0x00100B0C
 internal ParameterInfo[] GetIndexParametersNoCopy()
 {
     if (this.m_parameters == null)
     {
         int             num        = 0;
         ParameterInfo[] array      = null;
         MethodInfo      methodInfo = this.GetGetMethod(true);
         if (methodInfo != null)
         {
             array = methodInfo.GetParametersNoCopy();
             num   = array.Length;
         }
         else
         {
             methodInfo = this.GetSetMethod(true);
             if (methodInfo != null)
             {
                 array = methodInfo.GetParametersNoCopy();
                 num   = array.Length - 1;
             }
         }
         ParameterInfo[] array2 = new ParameterInfo[num];
         for (int i = 0; i < num; i++)
         {
             array2[i] = new RuntimeParameterInfo((RuntimeParameterInfo)array[i], this);
         }
         this.m_parameters = array2;
     }
     return(this.m_parameters);
 }
Example #4
0
 internal ParameterInfo[] GetIndexParametersNoCopy()
 {
     if (this.m_parameters == null)
     {
         int             length = 0;
         ParameterInfo[] parameterInfoArray1 = (ParameterInfo[])null;
         MethodInfo      getMethod           = this.GetGetMethod(true);
         if (getMethod != (MethodInfo)null)
         {
             parameterInfoArray1 = getMethod.GetParametersNoCopy();
             length = parameterInfoArray1.Length;
         }
         else
         {
             MethodInfo setMethod = this.GetSetMethod(true);
             if (setMethod != (MethodInfo)null)
             {
                 parameterInfoArray1 = setMethod.GetParametersNoCopy();
                 length = parameterInfoArray1.Length - 1;
             }
         }
         ParameterInfo[] parameterInfoArray2 = new ParameterInfo[length];
         for (int index = 0; index < length; ++index)
         {
             parameterInfoArray2[index] = (ParameterInfo) new RuntimeParameterInfo((RuntimeParameterInfo)parameterInfoArray1[index], this);
         }
         this.m_parameters = parameterInfoArray2;
     }
     return(this.m_parameters);
 }
Example #5
0
        internal ParameterInfo[] GetIndexParametersNoCopy()
        {
            // @History - Logic ported from RTM

            // No need to lock because we don't guarantee the uniqueness of ParameterInfo objects
            if (m_parameters == null)
            {
                int             numParams  = 0;
                ParameterInfo[] methParams = null;

                // First try to get the Get method.
                MethodInfo m = GetGetMethod(true);
                if (m != null)
                {
                    // There is a Get method so use it.
                    methParams = m.GetParametersNoCopy();
                    numParams  = methParams.Length;
                }
                else
                {
                    // If there is no Get method then use the Set method.
                    m = GetSetMethod(true);

                    if (m != null)
                    {
                        methParams = m.GetParametersNoCopy();
                        numParams  = methParams.Length - 1;
                    }
                }

                // Now copy over the parameter info's and change their
                // owning member info to the current property info.

                ParameterInfo[] propParams = new ParameterInfo[numParams];

                for (int i = 0; i < numParams; i++)
                {
                    propParams[i] = new RuntimeParameterInfo((RuntimeParameterInfo)methParams[i], this);
                }

                m_parameters = propParams;
            }

            return(m_parameters);
        }
Example #6
0
        public virtual void RemoveEventHandler(object target, Delegate handler)
        {
            MethodInfo removeMethod = GetRemoveMethod(nonPublic: false);

            if (removeMethod == null)
            {
                throw new InvalidOperationException(SR.InvalidOperation_NoPublicRemoveMethod);
            }

            ParameterInfo[] parameters = removeMethod.GetParametersNoCopy();
            if (parameters[0].ParameterType == typeof(EventRegistrationToken))
            {
                throw new InvalidOperationException(SR.InvalidOperation_NotSupportedOnWinRTEvent);
            }

            removeMethod.Invoke(target, new object[] { handler });
        }
        public virtual void RemoveEventHandler(object target, Delegate handler)
        {
            MethodInfo removeMethod = this.GetRemoveMethod();

            if (removeMethod == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoPublicRemoveMethod"));
            }
            ParameterInfo[] parametersNoCopy = removeMethod.GetParametersNoCopy();
            if (parametersNoCopy[0].ParameterType == typeof(EventRegistrationToken))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotSupportedOnWinRTEvent"));
            }
            removeMethod.Invoke(target, new object[]
            {
                handler
            });
        }
Example #8
0
        public virtual void RemoveEventHandler(object target, Delegate handler)
        {
            MethodInfo removeMethod = this.GetRemoveMethod();
            // ISSUE: variable of the null type
            __Null local = null;

            if (removeMethod == (MethodInfo)local)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoPublicRemoveMethod"));
            }
            if (removeMethod.GetParametersNoCopy()[0].ParameterType == typeof(EventRegistrationToken))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotSupportedOnWinRTEvent"));
            }
            object obj = target;

            object[] parameters = new object[1] {
                (object)handler
            };
            removeMethod.Invoke(obj, parameters);
        }
Example #9
0
        public virtual void RemoveEventHandler(Object target, Delegate handler)
        {
            MethodInfo removeMethod = GetRemoveMethod();

            if (removeMethod == null)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NoPublicRemoveMethod"));
            }

#if FEATURE_COMINTEROP
            ParameterInfo[] parameters = removeMethod.GetParametersNoCopy();
            Contract.Assert(parameters != null && parameters.Length == 1);

            if (parameters[0].ParameterType == typeof(System.Runtime.InteropServices.WindowsRuntime.EventRegistrationToken))
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_NotSupportedOnWinRTEvent"));
            }

            // Must be a normal non-WinRT event
            Contract.Assert(parameters[0].ParameterType.BaseType == typeof(MulticastDelegate));
#endif // FEATURE_COMINTEROP

            removeMethod.Invoke(target, new object[] { handler });
        }
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override void Emit(OpCode opcode, MethodInfo meth)
        {
            if (meth == null)
                throw new ArgumentNullException(nameof(meth));
            Contract.EndContractBlock();

            int stackchange = 0;
            int token = 0;
            DynamicMethod dynMeth = meth as DynamicMethod;
            if (dynMeth == null)
            {
                RuntimeMethodInfo rtMeth = meth as RuntimeMethodInfo;
                if (rtMeth == null)
                    throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), nameof(meth));

                RuntimeType declaringType = rtMeth.GetRuntimeType();
                if (declaringType != null && (declaringType.IsGenericType || declaringType.IsArray))
                    token = GetTokenFor(rtMeth, declaringType);
                else
                    token = GetTokenFor(rtMeth);
            }
            else
            {
                // rule out not allowed operations on DynamicMethods
                if (opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn))
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOpCodeOnDynamicMethod"));
                }
                token = GetTokenFor(dynMeth);
            }

            EnsureCapacity(7);
            InternalEmit(opcode);

            if (opcode.StackBehaviourPush == StackBehaviour.Varpush
                && meth.ReturnType != typeof(void))
            {
                stackchange++;
            }
            if (opcode.StackBehaviourPop == StackBehaviour.Varpop)
            {
                stackchange -= meth.GetParametersNoCopy().Length;
            }
            // Pop the "this" parameter if the method is non-static,
            //  and the instruction is not newobj/ldtoken/ldftn.
            if (!meth.IsStatic &&
                !(opcode.Equals(OpCodes.Newobj) || opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn)))
            {
                stackchange--;
            }

            UpdateStackSize(opcode, stackchange);

            PutInteger4(token);
        }
        //
        //
        // Token resolution calls
        //
        //
        public override void Emit(OpCode opcode, MethodInfo meth) { 
            if (meth == null) 
                throw new ArgumentNullException("meth");

            int stackchange = 0;
            int tempVal = 0;
            DynamicMethod dynMeth = DynamicMethod.AsDynamicMethod(meth);
            if (dynMeth == null) {
                if (!(meth is RuntimeMethodInfo))
                    throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "meth");               

                if (meth.DeclaringType != null && (meth.DeclaringType.IsGenericType || meth.DeclaringType.IsArray)) 
                    tempVal = m_scope.GetTokenFor(meth.MethodHandle, meth.DeclaringType.TypeHandle);
                else
                    tempVal = m_scope.GetTokenFor(meth.MethodHandle);
            }
            else {
                // rule out not allowed operations on DynamicMethods
                if (opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn) || opcode.Equals(OpCodes.Ldvirtftn)) {
                    throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOpCodeOnDynamicMethod"));
                }
                tempVal = m_scope.GetTokenFor(dynMeth);
            }

            EnsureCapacity(7);
            InternalEmit(opcode);

            if (opcode.m_push == StackBehaviour.Varpush 
                && meth.ReturnType != typeof(void)) {
                stackchange++;
            } 
            if (opcode.m_pop  == StackBehaviour.Varpop) { 
               stackchange -= meth.GetParametersNoCopy().Length;
            }
            // Pop the "this" parameter if the method is non-static,
            //  and the instruction is not newobj/ldtoken/ldftn.
            if (!meth.IsStatic &&
                !(opcode.Equals(OpCodes.Newobj) || opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn))) {
                stackchange--;
            }

            UpdateStackSize(opcode, stackchange);

            m_length=PutInteger4(tempVal, m_length, m_ILStream);
        }
Example #12
0
 /// <summary>
 /// 使用指定的类型转换方法初始化 <see cref="UserConversionMethod"/> 类的新实例。
 /// </summary>
 /// <param name="method">类型转换方法。</param>
 public UserConversionMethod(MethodInfo method)
 {
     Contract.Requires(method != null && method.GetParametersNoCopy().Length == 1);
     this.method = method;
     this.inputType = method.GetParametersNoCopy()[0].ParameterType;
 }
 public override void Emit(OpCode opcode, MethodInfo meth)
 {
     if (meth == null)
     {
         throw new ArgumentNullException("meth");
     }
     int stackchange = 0;
     int tokenFor = 0;
     DynamicMethod method = meth as DynamicMethod;
     if (method == null)
     {
         if (!(meth is RuntimeMethodInfo))
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_MustBeRuntimeMethodInfo"), "meth");
         }
         if ((meth.DeclaringType != null) && (meth.DeclaringType.IsGenericType || meth.DeclaringType.IsArray))
         {
             tokenFor = this.m_scope.GetTokenFor(meth.MethodHandle, meth.DeclaringType.TypeHandle);
         }
         else
         {
             tokenFor = this.m_scope.GetTokenFor(meth.MethodHandle);
         }
     }
     else
     {
         if ((opcode.Equals(OpCodes.Ldtoken) || opcode.Equals(OpCodes.Ldftn)) || opcode.Equals(OpCodes.Ldvirtftn))
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_InvalidOpCodeOnDynamicMethod"));
         }
         tokenFor = this.m_scope.GetTokenFor(method);
     }
     base.EnsureCapacity(7);
     base.InternalEmit(opcode);
     if ((opcode.m_push == StackBehaviour.Varpush) && (meth.ReturnType != typeof(void)))
     {
         stackchange++;
     }
     if (opcode.m_pop == StackBehaviour.Varpop)
     {
         stackchange -= meth.GetParametersNoCopy().Length;
     }
     if ((!meth.IsStatic && !opcode.Equals(OpCodes.Newobj)) && (!opcode.Equals(OpCodes.Ldtoken) && !opcode.Equals(OpCodes.Ldftn)))
     {
         stackchange--;
     }
     base.UpdateStackSize(opcode, stackchange);
     base.PutInteger4(tokenFor);
 }