예제 #1
0
 public override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
 {
     System.Reflection.MetadataToken metadataToken1 = new System.Reflection.MetadataToken(metadataToken);
     if (metadataToken1.IsGlobalTypeDefToken)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_ResolveModuleType", (object)metadataToken1), "metadataToken");
     }
     if (!this.MetadataImport.IsValidToken((int)metadataToken1))
     {
         throw new ArgumentOutOfRangeException("metadataToken", Environment.GetResourceString("Argument_InvalidToken", (object)metadataToken1, (object)this));
     }
     if (!metadataToken1.IsTypeDef && !metadataToken1.IsTypeSpec && !metadataToken1.IsTypeRef)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", (object)metadataToken1, (object)this), "metadataToken");
     }
     RuntimeTypeHandle[] typeHandleArray1 = RuntimeModule.ConvertToTypeHandleArray(genericTypeArguments);
     RuntimeTypeHandle[] typeHandleArray2 = RuntimeModule.ConvertToTypeHandleArray(genericMethodArguments);
     try
     {
         Type type = (Type)this.GetModuleHandle().ResolveTypeHandle(metadataToken, typeHandleArray1, typeHandleArray2).GetRuntimeType();
         if (type == (Type)null)
         {
             throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", (object)metadataToken1, (object)this), "metadataToken");
         }
         return(type);
     }
     catch (BadImageFormatException ex)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), (Exception)ex);
     }
 }
예제 #2
0
        public unsafe override FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
        {
            MetadataToken metadataToken2 = new MetadataToken(metadataToken);

            if (!this.MetadataImport.IsValidToken(metadataToken2))
            {
                throw new ArgumentOutOfRangeException("metadataToken", Environment.GetResourceString("Argument_InvalidToken", new object[]
                {
                    metadataToken2,
                    this
                }));
            }
            RuntimeTypeHandle[] typeInstantiationContext   = RuntimeModule.ConvertToTypeHandleArray(genericTypeArguments);
            RuntimeTypeHandle[] methodInstantiationContext = RuntimeModule.ConvertToTypeHandleArray(genericMethodArguments);
            FieldInfo           result;

            try
            {
                IRuntimeFieldInfo runtimeFieldInfo;
                if (!metadataToken2.IsFieldDef)
                {
                    if (!metadataToken2.IsMemberRef)
                    {
                        throw new ArgumentException("metadataToken", Environment.GetResourceString("Argument_ResolveField", new object[]
                        {
                            metadataToken2,
                            this
                        }));
                    }
                    if (*(byte *)this.MetadataImport.GetMemberRefProps(metadataToken2).Signature.ToPointer() != 6)
                    {
                        throw new ArgumentException("metadataToken", Environment.GetResourceString("Argument_ResolveField", new object[]
                        {
                            metadataToken2,
                            this
                        }));
                    }
                    runtimeFieldInfo = ModuleHandle.ResolveFieldHandleInternal(this.GetNativeHandle(), metadataToken2, typeInstantiationContext, methodInstantiationContext);
                }
                runtimeFieldInfo = ModuleHandle.ResolveFieldHandleInternal(this.GetNativeHandle(), metadataToken, typeInstantiationContext, methodInstantiationContext);
                RuntimeType runtimeType = RuntimeFieldHandle.GetApproxDeclaringType(runtimeFieldInfo.Value);
                if (runtimeType.IsGenericType || runtimeType.IsArray)
                {
                    int parentToken = ModuleHandle.GetMetadataImport(this.GetNativeHandle()).GetParentToken(metadataToken);
                    runtimeType = (RuntimeType)this.ResolveType(parentToken, genericTypeArguments, genericMethodArguments);
                }
                result = RuntimeType.GetFieldInfo(runtimeType, runtimeFieldInfo);
            }
            catch (MissingFieldException)
            {
                result = this.ResolveLiteralField(metadataToken2, genericTypeArguments, genericMethodArguments);
            }
            catch (BadImageFormatException innerException)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), innerException);
            }
            return(result);
        }
예제 #3
0
        public unsafe override MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
        {
            MetadataToken metadataToken2 = new MetadataToken(metadataToken);

            if (!this.MetadataImport.IsValidToken(metadataToken2))
            {
                throw new ArgumentOutOfRangeException("metadataToken", Environment.GetResourceString("Argument_InvalidToken", new object[]
                {
                    metadataToken2,
                    this
                }));
            }
            RuntimeTypeHandle[] typeInstantiationContext   = RuntimeModule.ConvertToTypeHandleArray(genericTypeArguments);
            RuntimeTypeHandle[] methodInstantiationContext = RuntimeModule.ConvertToTypeHandleArray(genericMethodArguments);
            MethodBase          methodBase;

            try
            {
                if (!metadataToken2.IsMethodDef && !metadataToken2.IsMethodSpec)
                {
                    if (!metadataToken2.IsMemberRef)
                    {
                        throw new ArgumentException("metadataToken", Environment.GetResourceString("Argument_ResolveMethod", new object[]
                        {
                            metadataToken2,
                            this
                        }));
                    }
                    if (*(byte *)this.MetadataImport.GetMemberRefProps(metadataToken2).Signature.ToPointer() == 6)
                    {
                        throw new ArgumentException("metadataToken", Environment.GetResourceString("Argument_ResolveMethod", new object[]
                        {
                            metadataToken2,
                            this
                        }));
                    }
                }
                IRuntimeMethodInfo runtimeMethodInfo = ModuleHandle.ResolveMethodHandleInternal(this.GetNativeHandle(), metadataToken2, typeInstantiationContext, methodInstantiationContext);
                Type type = RuntimeMethodHandle.GetDeclaringType(runtimeMethodInfo);
                if (type.IsGenericType || type.IsArray)
                {
                    MetadataToken token = new MetadataToken(this.MetadataImport.GetParentToken(metadataToken2));
                    if (metadataToken2.IsMethodSpec)
                    {
                        token = new MetadataToken(this.MetadataImport.GetParentToken(token));
                    }
                    type = this.ResolveType(token, genericTypeArguments, genericMethodArguments);
                }
                methodBase = RuntimeType.GetMethodBase(type as RuntimeType, runtimeMethodInfo);
            }
            catch (BadImageFormatException innerException)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), innerException);
            }
            return(methodBase);
        }
예제 #4
0
        public override Type ResolveType(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
        {
            MetadataToken metadataToken2 = new MetadataToken(metadataToken);

            if (metadataToken2.IsGlobalTypeDefToken)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_ResolveModuleType", new object[]
                {
                    metadataToken2
                }), "metadataToken");
            }
            if (!this.MetadataImport.IsValidToken(metadataToken2))
            {
                throw new ArgumentOutOfRangeException("metadataToken", Environment.GetResourceString("Argument_InvalidToken", new object[]
                {
                    metadataToken2,
                    this
                }));
            }
            if (!metadataToken2.IsTypeDef && !metadataToken2.IsTypeSpec && !metadataToken2.IsTypeRef)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", new object[]
                {
                    metadataToken2,
                    this
                }), "metadataToken");
            }
            RuntimeTypeHandle[] typeInstantiationContext   = RuntimeModule.ConvertToTypeHandleArray(genericTypeArguments);
            RuntimeTypeHandle[] methodInstantiationContext = RuntimeModule.ConvertToTypeHandleArray(genericMethodArguments);
            Type result;

            try
            {
                Type runtimeType = this.GetModuleHandle().ResolveTypeHandle(metadataToken, typeInstantiationContext, methodInstantiationContext).GetRuntimeType();
                if (runtimeType == null)
                {
                    throw new ArgumentException(Environment.GetResourceString("Argument_ResolveType", new object[]
                    {
                        metadataToken2,
                        this
                    }), "metadataToken");
                }
                result = runtimeType;
            }
            catch (BadImageFormatException innerException)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), innerException);
            }
            return(result);
        }
예제 #5
0
 public override unsafe FieldInfo ResolveField(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
 {
     System.Reflection.MetadataToken metadataToken1 = new System.Reflection.MetadataToken(metadataToken);
     if (!this.MetadataImport.IsValidToken((int)metadataToken1))
     {
         throw new ArgumentOutOfRangeException("metadataToken", Environment.GetResourceString("Argument_InvalidToken", (object)metadataToken1, (object)this));
     }
     RuntimeTypeHandle[] typeHandleArray1 = RuntimeModule.ConvertToTypeHandleArray(genericTypeArguments);
     RuntimeTypeHandle[] typeHandleArray2 = RuntimeModule.ConvertToTypeHandleArray(genericMethodArguments);
     try
     {
         IRuntimeFieldInfo runtimeFieldInfo = (IRuntimeFieldInfo)null;
         if (!metadataToken1.IsFieldDef)
         {
             if (!metadataToken1.IsMemberRef)
             {
                 throw new ArgumentException("metadataToken", Environment.GetResourceString("Argument_ResolveField", (object)metadataToken1, (object)this));
             }
             if ((int)*(byte *)this.MetadataImport.GetMemberRefProps((int)metadataToken1).Signature.ToPointer() != 6)
             {
                 throw new ArgumentException("metadataToken", Environment.GetResourceString("Argument_ResolveField", (object)metadataToken1, (object)this));
             }
             runtimeFieldInfo = ModuleHandle.ResolveFieldHandleInternal(this.GetNativeHandle(), (int)metadataToken1, typeHandleArray1, typeHandleArray2);
         }
         IRuntimeFieldInfo field         = ModuleHandle.ResolveFieldHandleInternal(this.GetNativeHandle(), metadataToken, typeHandleArray1, typeHandleArray2);
         RuntimeType       reflectedType = RuntimeFieldHandle.GetApproxDeclaringType(field.Value);
         if (reflectedType.IsGenericType || reflectedType.IsArray)
         {
             reflectedType = (RuntimeType)this.ResolveType(ModuleHandle.GetMetadataImport(this.GetNativeHandle()).GetParentToken(metadataToken), genericTypeArguments, genericMethodArguments);
         }
         return(RuntimeType.GetFieldInfo(reflectedType, field));
     }
     catch (MissingFieldException ex)
     {
         return(this.ResolveLiteralField((int)metadataToken1, genericTypeArguments, genericMethodArguments));
     }
     catch (BadImageFormatException ex)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), (Exception)ex);
     }
 }
예제 #6
0
 public override unsafe MethodBase ResolveMethod(int metadataToken, Type[] genericTypeArguments, Type[] genericMethodArguments)
 {
     System.Reflection.MetadataToken metadataToken1 = new System.Reflection.MetadataToken(metadataToken);
     if (!this.MetadataImport.IsValidToken((int)metadataToken1))
     {
         throw new ArgumentOutOfRangeException("metadataToken", Environment.GetResourceString("Argument_InvalidToken", (object)metadataToken1, (object)this));
     }
     RuntimeTypeHandle[] typeHandleArray1 = RuntimeModule.ConvertToTypeHandleArray(genericTypeArguments);
     RuntimeTypeHandle[] typeHandleArray2 = RuntimeModule.ConvertToTypeHandleArray(genericMethodArguments);
     try
     {
         if (!metadataToken1.IsMethodDef && !metadataToken1.IsMethodSpec)
         {
             if (!metadataToken1.IsMemberRef)
             {
                 throw new ArgumentException("metadataToken", Environment.GetResourceString("Argument_ResolveMethod", (object)metadataToken1, (object)this));
             }
             if ((int)*(byte *)this.MetadataImport.GetMemberRefProps((int)metadataToken1).Signature.ToPointer() == 6)
             {
                 throw new ArgumentException("metadataToken", Environment.GetResourceString("Argument_ResolveMethod", (object)metadataToken1, (object)this));
             }
         }
         IRuntimeMethodInfo runtimeMethodInfo = ModuleHandle.ResolveMethodHandleInternal(this.GetNativeHandle(), (int)metadataToken1, typeHandleArray1, typeHandleArray2);
         Type type = (Type)RuntimeMethodHandle.GetDeclaringType(runtimeMethodInfo);
         if (type.IsGenericType || type.IsArray)
         {
             System.Reflection.MetadataToken metadataToken2 = new System.Reflection.MetadataToken(this.MetadataImport.GetParentToken((int)metadataToken1));
             if (metadataToken1.IsMethodSpec)
             {
                 metadataToken2 = new System.Reflection.MetadataToken(this.MetadataImport.GetParentToken((int)metadataToken2));
             }
             type = this.ResolveType((int)metadataToken2, genericTypeArguments, genericMethodArguments);
         }
         return(RuntimeType.GetMethodBase(type as RuntimeType, runtimeMethodInfo));
     }
     catch (BadImageFormatException ex)
     {
         throw new ArgumentException(Environment.GetResourceString("Argument_BadImageFormatExceptionResolve"), (Exception)ex);
     }
 }