GetParamDefProps() public method

public GetParamDefProps ( int parameterToken, int &sequence, ParameterAttributes &attributes ) : void
parameterToken int
sequence int
attributes ParameterAttributes
return void
Esempio n. 1
0
        internal static unsafe ParameterInfo[] GetParameters(MethodBase method, MemberInfo member, Signature sig, out ParameterInfo returnParameter, bool fetchReturnParameter)
        {
            RuntimeMethodHandle methodHandle = method.GetMethodHandle();

            returnParameter = null;
            int length = sig.Arguments.Length;

            ParameterInfo[] infoArray = fetchReturnParameter ? null : new ParameterInfo[length];
            int             methodDef = methodHandle.GetMethodDef();
            int             count     = 0;

            if (!System.Reflection.MetadataToken.IsNullToken(methodDef))
            {
                MetadataImport metadataImport = methodHandle.GetDeclaringType().GetModuleHandle().GetMetadataImport();
                count = metadataImport.EnumParamsCount(methodDef);
                int *result = stackalloc int[count];
                metadataImport.EnumParams(methodDef, result, count);
                for (uint i = 0; i < count; i++)
                {
                    ParameterAttributes attributes;
                    int num5;
                    int parameterToken = result[(int)((int *)i)];
                    metadataImport.GetParamDefProps(parameterToken, out num5, out attributes);
                    num5--;
                    if (fetchReturnParameter && (num5 == -1))
                    {
                        returnParameter = new ParameterInfo(sig, metadataImport, parameterToken, num5, attributes, member);
                    }
                    else if (!fetchReturnParameter && (num5 >= 0))
                    {
                        infoArray[num5] = new ParameterInfo(sig, metadataImport, parameterToken, num5, attributes, member);
                    }
                }
            }
            if (fetchReturnParameter)
            {
                if (returnParameter == null)
                {
                    returnParameter = new ParameterInfo(sig, MetadataImport.EmptyImport, 0, -1, ParameterAttributes.None, member);
                }
                return(infoArray);
            }
            if (count < (infoArray.Length + 1))
            {
                for (int j = 0; j < infoArray.Length; j++)
                {
                    if (infoArray[j] == null)
                    {
                        infoArray[j] = new ParameterInfo(sig, MetadataImport.EmptyImport, 0, j, ParameterAttributes.None, member);
                    }
                }
            }
            return(infoArray);
        }
Esempio n. 2
0
        [System.Security.SecurityCritical]  // auto-generated
        internal unsafe static ParameterInfo[] GetParameters(
            IRuntimeMethodInfo methodHandle, MemberInfo member, Signature sig, out ParameterInfo returnParameter, bool fetchReturnParameter)
        {
            returnParameter = null;
            int sigArgCount = sig.Arguments.Length;

            ParameterInfo[] args = fetchReturnParameter ? null : new ParameterInfo[sigArgCount];

            int tkMethodDef = RuntimeMethodHandle.GetMethodDef(methodHandle);
            int cParamDefs  = 0;

            // Not all methods have tokens. Arrays, pointers and byRef types do not have tokens as they
            // are generated on the fly by the runtime.
            if (!MdToken.IsNullToken(tkMethodDef))
            {
                MetadataImport scope = RuntimeTypeHandle.GetMetadataImport(RuntimeMethodHandle.GetDeclaringType(methodHandle));

                MetadataEnumResult tkParamDefs;
                scope.EnumParams(tkMethodDef, out tkParamDefs);

                cParamDefs = tkParamDefs.Length;

                // Not all parameters have tokens. Parameters may have no token
                // if they have no name and no attributes.
                if (cParamDefs > sigArgCount + 1 /* return type */)
                {
                    throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                }

                for (int i = 0; i < cParamDefs; i++)
                {
                    #region Populate ParameterInfos
                    ParameterAttributes attr;
                    int position, tkParamDef = tkParamDefs[i];

                    scope.GetParamDefProps(tkParamDef, out position, out attr);

                    position--;

                    if (fetchReturnParameter == true && position == -1)
                    {
                        // more than one return parameter?
                        if (returnParameter != null)
                        {
                            throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                        }

                        returnParameter = new RuntimeParameterInfo(sig, scope, tkParamDef, position, attr, member);
                    }
                    else if (fetchReturnParameter == false && position >= 0)
                    {
                        // position beyong sigArgCount?
                        if (position >= sigArgCount)
                        {
                            throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                        }

                        args[position] = new RuntimeParameterInfo(sig, scope, tkParamDef, position, attr, member);
                    }
                    #endregion
                }
            }

            // Fill in empty ParameterInfos for those without tokens
            if (fetchReturnParameter)
            {
                if (returnParameter == null)
                {
                    returnParameter = new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, -1, (ParameterAttributes)0, member);
                }
            }
            else
            {
                if (cParamDefs < args.Length + 1)
                {
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i] != null)
                        {
                            continue;
                        }

                        args[i] = new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, i, (ParameterAttributes)0, member);
                    }
                }
            }

            return(args);
        }
Esempio n. 3
0
        internal static unsafe ParameterInfo[] GetParameters(IRuntimeMethodInfo methodHandle, MemberInfo member, Signature sig, out ParameterInfo returnParameter, bool fetchReturnParameter)
        {
            returnParameter = null;
            int length = sig.Arguments.Length;

            ParameterInfo[] infoArray = fetchReturnParameter ? null : new ParameterInfo[length];
            int             methodDef = RuntimeMethodHandle.GetMethodDef(methodHandle);
            int             count     = 0;

            if (!System.Reflection.MetadataToken.IsNullToken(methodDef))
            {
                MetadataImport metadataImport = RuntimeTypeHandle.GetMetadataImport(RuntimeMethodHandle.GetDeclaringType(methodHandle));
                count = metadataImport.EnumParamsCount(methodDef);
                int *result = (int *)stackalloc byte[(((IntPtr)count) * 4)];
                metadataImport.EnumParams(methodDef, result, count);
                if (count > (length + 1))
                {
                    throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                }
                for (uint i = 0; i < count; i++)
                {
                    ParameterAttributes attributes;
                    int num5;
                    int parameterToken = result[(int)((int *)i)];
                    metadataImport.GetParamDefProps(parameterToken, out num5, out attributes);
                    num5--;
                    if (fetchReturnParameter && (num5 == -1))
                    {
                        if (returnParameter != null)
                        {
                            throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                        }
                        returnParameter = new RuntimeParameterInfo(sig, metadataImport, parameterToken, num5, attributes, member);
                    }
                    else if (!fetchReturnParameter && (num5 >= 0))
                    {
                        if (num5 >= length)
                        {
                            throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                        }
                        infoArray[num5] = new RuntimeParameterInfo(sig, metadataImport, parameterToken, num5, attributes, member);
                    }
                }
            }
            if (fetchReturnParameter)
            {
                if (returnParameter == null)
                {
                    returnParameter = new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, -1, ParameterAttributes.None, member);
                }
                return(infoArray);
            }
            if (count < (infoArray.Length + 1))
            {
                for (int j = 0; j < infoArray.Length; j++)
                {
                    if (infoArray[j] == null)
                    {
                        infoArray[j] = new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, j, ParameterAttributes.None, member);
                    }
                }
            }
            return(infoArray);
        }
        internal static ParameterInfo[] GetParameters(IRuntimeMethodInfo methodHandle, MemberInfo member, Signature sig, out ParameterInfo returnParameter, bool fetchReturnParameter)
        {
            returnParameter = null;
            int num = sig.Arguments.Length;

            ParameterInfo[] array     = fetchReturnParameter ? null : new ParameterInfo[num];
            int             methodDef = RuntimeMethodHandle.GetMethodDef(methodHandle);
            int             num2      = 0;

            if (!System.Reflection.MetadataToken.IsNullToken(methodDef))
            {
                MetadataImport     metadataImport = RuntimeTypeHandle.GetMetadataImport(RuntimeMethodHandle.GetDeclaringType(methodHandle));
                MetadataEnumResult metadataEnumResult;
                metadataImport.EnumParams(methodDef, out metadataEnumResult);
                num2 = metadataEnumResult.Length;
                if (num2 > num + 1)
                {
                    throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                }
                for (int i = 0; i < num2; i++)
                {
                    int num3 = metadataEnumResult[i];
                    int num4;
                    ParameterAttributes attributes;
                    metadataImport.GetParamDefProps(num3, out num4, out attributes);
                    num4--;
                    if (fetchReturnParameter && num4 == -1)
                    {
                        if (returnParameter != null)
                        {
                            throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                        }
                        returnParameter = new RuntimeParameterInfo(sig, metadataImport, num3, num4, attributes, member);
                    }
                    else if (!fetchReturnParameter && num4 >= 0)
                    {
                        if (num4 >= num)
                        {
                            throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                        }
                        array[num4] = new RuntimeParameterInfo(sig, metadataImport, num3, num4, attributes, member);
                    }
                }
            }
            if (fetchReturnParameter)
            {
                if (returnParameter == null)
                {
                    returnParameter = new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, -1, ParameterAttributes.None, member);
                }
            }
            else if (num2 < array.Length + 1)
            {
                for (int j = 0; j < array.Length; j++)
                {
                    if (array[j] == null)
                    {
                        array[j] = new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, j, ParameterAttributes.None, member);
                    }
                }
            }
            return(array);
        }
Esempio n. 5
0
        internal static ParameterInfo[] GetParameters(IRuntimeMethodInfo methodHandle, MemberInfo member, Signature sig, out ParameterInfo returnParameter, bool fetchReturnParameter)
        {
            returnParameter = (ParameterInfo)null;
            int length = sig.Arguments.Length;

            ParameterInfo[] parameterInfoArray = fetchReturnParameter ? (ParameterInfo[])null : new ParameterInfo[length];
            int             methodDef          = RuntimeMethodHandle.GetMethodDef(methodHandle);
            int             num1 = 0;

            if (!System.Reflection.MetadataToken.IsNullToken(methodDef))
            {
                MetadataImport     metadataImport = RuntimeTypeHandle.GetMetadataImport(RuntimeMethodHandle.GetDeclaringType(methodHandle));
                MetadataEnumResult result;
                metadataImport.EnumParams(methodDef, out result);
                num1 = result.Length;
                if (num1 > length + 1)
                {
                    throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                }
                for (int index = 0; index < num1; ++index)
                {
                    int num2 = result[index];
                    int sequence;
                    ParameterAttributes attributes;
                    metadataImport.GetParamDefProps(num2, out sequence, out attributes);
                    --sequence;
                    if (fetchReturnParameter && sequence == -1)
                    {
                        if (returnParameter != null)
                        {
                            throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                        }
                        returnParameter = (ParameterInfo) new RuntimeParameterInfo(sig, metadataImport, num2, sequence, attributes, member);
                    }
                    else if (!fetchReturnParameter && sequence >= 0)
                    {
                        if (sequence >= length)
                        {
                            throw new BadImageFormatException(Environment.GetResourceString("BadImageFormat_ParameterSignatureMismatch"));
                        }
                        parameterInfoArray[sequence] = (ParameterInfo) new RuntimeParameterInfo(sig, metadataImport, num2, sequence, attributes, member);
                    }
                }
            }
            if (fetchReturnParameter)
            {
                if (returnParameter == null)
                {
                    returnParameter = (ParameterInfo) new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, -1, ParameterAttributes.None, member);
                }
            }
            else if (num1 < parameterInfoArray.Length + 1)
            {
                for (int position = 0; position < parameterInfoArray.Length; ++position)
                {
                    if (parameterInfoArray[position] == null)
                    {
                        parameterInfoArray[position] = (ParameterInfo) new RuntimeParameterInfo(sig, MetadataImport.EmptyImport, 0, position, ParameterAttributes.None, member);
                    }
                }
            }
            return(parameterInfoArray);
        }