EnumParamsCount() public method

public EnumParamsCount ( int mdMethodDef ) : int
mdMethodDef int
return int
Exemplo 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);
        }
Exemplo n.º 2
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);
        }