GetMemberRefProps() публичный Метод

public GetMemberRefProps ( int memberTokenRef ) : ConstArray
memberTokenRef int
Результат ConstArray
Пример #1
0
        public override MethodBase?ResolveMethod(int metadataToken, Type[]?genericTypeArguments, Type[]?genericMethodArguments)
        {
            try
            {
                MetadataToken tk = new MetadataToken(metadataToken);
                if (!tk.IsMethodDef && !tk.IsMethodSpec)
                {
                    if (!tk.IsMemberRef)
                    {
                        throw new ArgumentException(SR.Format(SR.Argument_ResolveMethod, tk, this),
                                                    nameof(metadataToken));
                    }

                    unsafe
                    {
                        ConstArray sig = MetadataImport.GetMemberRefProps(tk);

                        if (*(MdSigCallingConvention *)sig.Signature == MdSigCallingConvention.Field)
                        {
                            throw new ArgumentException(SR.Format(SR.Argument_ResolveMethod, tk, this),
                                                        nameof(metadataToken));
                        }
                    }
                }

                RuntimeTypeHandle[]? typeArgs   = null;
                RuntimeTypeHandle[]? methodArgs = null;
                if (genericTypeArguments?.Length > 0)
                {
                    typeArgs = ConvertToTypeHandleArray(genericTypeArguments);
                }
                if (genericMethodArguments?.Length > 0)
                {
                    methodArgs = ConvertToTypeHandleArray(genericMethodArguments);
                }

                ModuleHandle       moduleHandle = new ModuleHandle(this);
                IRuntimeMethodInfo methodHandle = moduleHandle.ResolveMethodHandle(tk, typeArgs, methodArgs).GetMethodInfo();

                Type declaringType = RuntimeMethodHandle.GetDeclaringType(methodHandle);

                if (declaringType.IsGenericType || declaringType.IsArray)
                {
                    MetadataToken tkDeclaringType = new MetadataToken(MetadataImport.GetParentToken(tk));

                    if (tk.IsMethodSpec)
                    {
                        tkDeclaringType = new MetadataToken(MetadataImport.GetParentToken(tkDeclaringType));
                    }

                    declaringType = ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
                }

                return(RuntimeType.GetMethodBase(declaringType as RuntimeType, methodHandle));
            }
            catch (BadImageFormatException e)
            {
                throw new ArgumentException(SR.Argument_BadImageFormatExceptionResolve, e);
            }
        }
Пример #2
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
        {
            MetadataToken tk = new MetadataToken(metadataToken);

            if (!MetadataImport.IsValidToken(tk))
            {
                throw new ArgumentOutOfRangeException("metadataToken",
                                                      Environment.GetResourceString("Argument_InvalidToken", tk, this));
            }

            RuntimeTypeHandle[] typeArgs   = ConvertToTypeHandleArray(genericTypeArguments);
            RuntimeTypeHandle[] methodArgs = ConvertToTypeHandleArray(genericMethodArguments);

            try
            {
                IRuntimeFieldInfo fieldHandle = null;

                if (!tk.IsFieldDef)
                {
                    if (!tk.IsMemberRef)
                    {
                        throw new ArgumentException("metadataToken",
                                                    Environment.GetResourceString("Argument_ResolveField", tk, this));
                    }

                    unsafe
                    {
                        ConstArray sig = MetadataImport.GetMemberRefProps(tk);

                        if (*(MdSigCallingConvention *)sig.Signature.ToPointer() != MdSigCallingConvention.Field)
                        {
                            throw new ArgumentException("metadataToken",
                                                        Environment.GetResourceString("Argument_ResolveField", tk, this));
                        }
                    }

                    fieldHandle = ModuleHandle.ResolveFieldHandleInternal(GetNativeHandle(), tk, typeArgs, methodArgs);
                }

                fieldHandle = ModuleHandle.ResolveFieldHandleInternal(GetNativeHandle(), metadataToken, typeArgs, methodArgs);
                RuntimeType declaringType = RuntimeFieldHandle.GetApproxDeclaringType(fieldHandle.Value);

                if (declaringType.IsGenericType || declaringType.IsArray)
                {
                    int tkDeclaringType = ModuleHandle.GetMetadataImport(GetNativeHandle()).GetParentToken(metadataToken);
                    declaringType = (RuntimeType)ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
                }

                return(System.RuntimeType.GetFieldInfo(declaringType, fieldHandle));
            }
            catch (MissingFieldException)
            {
                return(ResolveLiteralField(tk, genericTypeArguments, genericMethodArguments));
            }
            catch (BadImageFormatException e)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), e);
            }
        }
Пример #3
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
        {
            MetadataToken tk = new MetadataToken(metadataToken);

            if (!MetadataImport.IsValidToken(tk))
            {
                throw new ArgumentOutOfRangeException("metadataToken",
                                                      Environment.GetResourceString("Argument_InvalidToken", tk, this));
            }

            RuntimeTypeHandle[] typeArgs   = ConvertToTypeHandleArray(genericTypeArguments);
            RuntimeTypeHandle[] methodArgs = ConvertToTypeHandleArray(genericMethodArguments);

            try
            {
                if (!tk.IsMethodDef && !tk.IsMethodSpec)
                {
                    if (!tk.IsMemberRef)
                    {
                        throw new ArgumentException("metadataToken",
                                                    Environment.GetResourceString("Argument_ResolveMethod", tk, this));
                    }

                    unsafe
                    {
                        ConstArray sig = MetadataImport.GetMemberRefProps(tk);

                        if (*(MdSigCallingConvention *)sig.Signature.ToPointer() == MdSigCallingConvention.Field)
                        {
                            throw new ArgumentException("metadataToken",
                                                        Environment.GetResourceString("Argument_ResolveMethod", tk, this));
                        }
                    }
                }

                IRuntimeMethodInfo methodHandle = ModuleHandle.ResolveMethodHandleInternal(GetNativeHandle(), tk, typeArgs, methodArgs);
                Type declaringType = RuntimeMethodHandle.GetDeclaringType(methodHandle);

                if (declaringType.IsGenericType || declaringType.IsArray)
                {
                    MetadataToken tkDeclaringType = new MetadataToken(MetadataImport.GetParentToken(tk));

                    if (tk.IsMethodSpec)
                    {
                        tkDeclaringType = new MetadataToken(MetadataImport.GetParentToken(tkDeclaringType));
                    }

                    declaringType = ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
                }

                return(System.RuntimeType.GetMethodBase(declaringType as RuntimeType, methodHandle));
            }
            catch (BadImageFormatException e)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), e);
            }
        }
Пример #4
0
        [System.Security.SecuritySafeCritical]  // auto-generated
        public override MemberInfo ResolveMember(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
        {
            MetadataToken tk = new MetadataToken(metadataToken);

            if (tk.IsProperty)
            {
                throw new ArgumentException(Environment.GetResourceString("InvalidOperation_PropertyInfoNotAvailable"));
            }

            if (tk.IsEvent)
            {
                throw new ArgumentException(Environment.GetResourceString("InvalidOperation_EventInfoNotAvailable"));
            }

            if (tk.IsMethodSpec || tk.IsMethodDef)
            {
                return(ResolveMethod(metadataToken, genericTypeArguments, genericMethodArguments));
            }

            if (tk.IsFieldDef)
            {
                return(ResolveField(metadataToken, genericTypeArguments, genericMethodArguments));
            }

            if (tk.IsTypeRef || tk.IsTypeDef || tk.IsTypeSpec)
            {
                return(ResolveType(metadataToken, genericTypeArguments, genericMethodArguments));
            }

            if (tk.IsMemberRef)
            {
                if (!MetadataImport.IsValidToken(tk))
                {
                    throw new ArgumentOutOfRangeException("metadataToken",
                                                          Environment.GetResourceString("Argument_InvalidToken", tk, this));
                }

                ConstArray sig = MetadataImport.GetMemberRefProps(tk);

                unsafe
                {
                    if (*(MdSigCallingConvention *)sig.Signature.ToPointer() == MdSigCallingConvention.Field)
                    {
                        return(ResolveField(tk, genericTypeArguments, genericMethodArguments));
                    }
                    else
                    {
                        return(ResolveMethod(tk, genericTypeArguments, genericMethodArguments));
                    }
                }
            }

            throw new ArgumentException("metadataToken",
                                        Environment.GetResourceString("Argument_ResolveMember", tk, this));
        }
Пример #5
0
        public override MemberInfo?ResolveMember(int metadataToken, Type[]?genericTypeArguments, Type[]?genericMethodArguments)
        {
            MetadataToken tk = new MetadataToken(metadataToken);

            if (tk.IsProperty)
            {
                throw new ArgumentException(SR.InvalidOperation_PropertyInfoNotAvailable);
            }

            if (tk.IsEvent)
            {
                throw new ArgumentException(SR.InvalidOperation_EventInfoNotAvailable);
            }

            if (tk.IsMethodSpec || tk.IsMethodDef)
            {
                return(ResolveMethod(metadataToken, genericTypeArguments, genericMethodArguments));
            }

            if (tk.IsFieldDef)
            {
                return(ResolveField(metadataToken, genericTypeArguments, genericMethodArguments));
            }

            if (tk.IsTypeRef || tk.IsTypeDef || tk.IsTypeSpec)
            {
                return(ResolveType(metadataToken, genericTypeArguments, genericMethodArguments));
            }

            if (tk.IsMemberRef)
            {
                if (!MetadataImport.IsValidToken(tk))
                {
                    throw new ArgumentOutOfRangeException(nameof(metadataToken),
                                                          SR.Format(SR.Argument_InvalidToken, tk, this));
                }

                ConstArray sig = MetadataImport.GetMemberRefProps(tk);

                unsafe
                {
                    if (*(MdSigCallingConvention *)sig.Signature == MdSigCallingConvention.Field)
                    {
                        return(ResolveField(tk, genericTypeArguments, genericMethodArguments));
                    }
                    else
                    {
                        return(ResolveMethod(tk, genericTypeArguments, genericMethodArguments));
                    }
                }
            }

            throw new ArgumentException(SR.Format(SR.Argument_ResolveMember, tk, this),
                                        nameof(metadataToken));
        }
Пример #6
0
        public override byte[] ResolveSignature(int metadataToken)
        {
            MetadataToken tk = new MetadataToken(metadataToken);

            if (!MetadataImport.IsValidToken(tk))
            {
                throw new ArgumentOutOfRangeException(
                          nameof(metadataToken),
                          SR.Format(SR.Argument_InvalidToken, tk, this)
                          );
            }

            if (
                !tk.IsMemberRef &&
                !tk.IsMethodDef &&
                !tk.IsTypeSpec &&
                !tk.IsSignature &&
                !tk.IsFieldDef
                )
            {
                throw new ArgumentException(
                          SR.Format(SR.Argument_InvalidToken, tk, this),
                          nameof(metadataToken)
                          );
            }

            ConstArray signature;

            if (tk.IsMemberRef)
            {
                signature = MetadataImport.GetMemberRefProps(metadataToken);
            }
            else
            {
                signature = MetadataImport.GetSignatureFromToken(metadataToken);
            }

            byte[] sig = new byte[signature.Length];

            for (int i = 0; i < signature.Length; i++)
            {
                sig[i] = signature[i];
            }

            return(sig);
        }
Пример #7
0
        public byte[] ResolveSignature(int metadataToken)
        {
            MetadataToken tk = new MetadataToken(metadataToken);

            if (!MetadataImport.IsValidToken(tk))
            {
                throw new ArgumentOutOfRangeException("metadataToken",
                                                      String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidToken", tk, this)));
            }

            if (!tk.IsMemberRef && !tk.IsMethodDef && !tk.IsTypeSpec && !tk.IsSignature && !tk.IsFieldDef)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Argument_InvalidToken", tk, this)),
                                            "metadataToken");
            }

            ConstArray signature;

            if (tk.IsMemberRef)
            {
                signature = MetadataImport.GetMemberRefProps(metadataToken);
            }
            else
            {
                signature = MetadataImport.GetSignatureFromToken(metadataToken);
            }

            byte[] sig = new byte[signature.Length];

            for (int i = 0; i < signature.Length; i++)
            {
                sig[i] = signature[i];
            }

            return(sig);
        }
Пример #8
0
        public override FieldInfo?ResolveField(int metadataToken, Type[]?genericTypeArguments, Type[]?genericMethodArguments)
        {
            try
            {
                MetadataToken tk = new MetadataToken(metadataToken);

                if (!MetadataImport.IsValidToken(tk))
                {
                    throw new ArgumentOutOfRangeException(nameof(metadataToken),
                                                          SR.Format(SR.Argument_InvalidToken, tk, this));
                }

                RuntimeTypeHandle[]? typeArgs   = null;
                RuntimeTypeHandle[]? methodArgs = null;
                if (genericTypeArguments?.Length > 0)
                {
                    typeArgs = ConvertToTypeHandleArray(genericTypeArguments);
                }
                if (genericMethodArguments?.Length > 0)
                {
                    methodArgs = ConvertToTypeHandleArray(genericMethodArguments);
                }

                ModuleHandle moduleHandle = new ModuleHandle(this);
                if (!tk.IsFieldDef)
                {
                    if (!tk.IsMemberRef)
                    {
                        throw new ArgumentException(SR.Format(SR.Argument_ResolveField, tk, this),
                                                    nameof(metadataToken));
                    }

                    unsafe
                    {
                        ConstArray sig = MetadataImport.GetMemberRefProps(tk);

                        if (*(MdSigCallingConvention *)sig.Signature != MdSigCallingConvention.Field)
                        {
                            throw new ArgumentException(SR.Format(SR.Argument_ResolveField, tk, this),
                                                        nameof(metadataToken));
                        }
                    }
                }

                IRuntimeFieldInfo fieldHandle = moduleHandle.ResolveFieldHandle(metadataToken, typeArgs, methodArgs).GetRuntimeFieldInfo();

                RuntimeType declaringType = RuntimeFieldHandle.GetApproxDeclaringType(fieldHandle.Value);

                if (declaringType.IsGenericType || declaringType.IsArray)
                {
                    int tkDeclaringType = ModuleHandle.GetMetadataImport(this).GetParentToken(metadataToken);
                    declaringType = (RuntimeType)ResolveType(tkDeclaringType, genericTypeArguments, genericMethodArguments);
                }

                return(RuntimeType.GetFieldInfo(declaringType, fieldHandle));
            }
            catch (MissingFieldException)
            {
                return(ResolveLiteralField(metadataToken, genericTypeArguments, genericMethodArguments));
            }
            catch (BadImageFormatException e)
            {
                throw new ArgumentException(SR.Argument_BadImageFormatExceptionResolve, e);
            }
        }