private RuntimeFatMethodParameterInfo(MethodBase member, MethodHandle methodHandle, int position, ParameterHandle parameterHandle, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
     : base(member, position, reflectionDomain, reader, typeHandle, typeContext)
 {
     _methodHandle = methodHandle;
     _parameterHandle = parameterHandle;
     _parameter = parameterHandle.GetParameter(reader);
 }
示例#2
0
        public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
        {
            result = null;
            RuntimeType genericType;
            Exception   typeLoadException = GenericType.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out genericType);

            if (typeLoadException != null)
            {
                return(typeLoadException);
            }
            LowLevelList <RuntimeType> genericTypeArguments = new LowLevelList <RuntimeType>();

            foreach (TypeName genericTypeArgumentName in GenericArguments)
            {
                RuntimeType genericTypeArgument;
                typeLoadException = genericTypeArgumentName.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out genericTypeArgument);
                if (typeLoadException != null)
                {
                    return(typeLoadException);
                }
                genericTypeArguments.Add(genericTypeArgument);
            }
            result = ReflectionCoreNonPortable.GetConstructedGenericType(genericType, genericTypeArguments.ToArray());
            return(null);
        }
示例#3
0
文件: Dispensers.cs 项目: rivy/corert
 internal static IEnumerable <CustomAttributeData> GetCustomAttributes(ReflectionDomain reflectionDomain, MetadataReader reader, IEnumerable <CustomAttributeHandle> customAttributeHandles)
 {
     foreach (CustomAttributeHandle customAttributeHandle in customAttributeHandles)
     {
         yield return(GetCustomAttributeData(reflectionDomain, reader, customAttributeHandle));
     }
 }
示例#4
0
        public sealed override String ToString()
        {
            StringBuilder sb = new StringBuilder(30);

            ReflectionDomain reflectionDomain = _contextTypeInfo.ReflectionDomain;
            TypeContext      typeContext      = _contextTypeInfo.TypeContext;
            Handle           typeHandle       = _property.Signature.GetPropertySignature(_reader).Type;

            sb.Append(typeHandle.FormatTypeName(_reader, typeContext, reflectionDomain));
            sb.Append(' ');
            sb.Append(this.Name);
            ParameterInfo[] indexParameters = this.GetIndexParameters();
            if (indexParameters.Length != 0)
            {
                RuntimeParameterInfo[] indexRuntimeParameters = new RuntimeParameterInfo[indexParameters.Length];
                for (int i = 0; i < indexParameters.Length; i++)
                {
                    indexRuntimeParameters[i] = (RuntimeParameterInfo)(indexParameters[i]);
                }
                sb.Append(" [");
                sb.Append(RuntimeMethodCommon.ComputeParametersString(indexRuntimeParameters, 0));
                sb.Append(']');
            }

            return(sb.ToString());
        }
 protected RuntimeMethodParameterInfo(MethodBase member, int position, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
     : base(member, position)
 {
     _reflectionDomain = reflectionDomain;
     Reader = reader;
     _typeHandle = typeHandle;
     _typeContext = typeContext;
 }
 protected RuntimeMethodParameterInfo(MethodBase member, int position, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
     : base(member, position)
 {
     _reflectionDomain = reflectionDomain;
     Reader            = reader;
     _typeHandle       = typeHandle;
     _typeContext      = typeContext;
 }
示例#7
0
        private static LowLevelDictionary <String, QHandle> CreateCaseInsensitiveTypeDictionary(RuntimeAssembly assembly)
        {
            //
            // Collect all of the *non-nested* types and type-forwards.
            //
            //   The keys are full typenames in lower-cased form.
            //   The value is a tuple containing either a TypeDefinitionHandle or TypeForwarderHandle and the associated Reader
            //      for that handle.
            //
            // We do not store nested types here. The container type is resolved and chosen first, then the nested type chosen from
            // that. If we chose the wrong container type and fail the match as a result, that's too bad. (The desktop CLR has the
            // same issue.)
            //
            ReflectionDomain reflectionDomain         = assembly.ReflectionDomain;
            LowLevelDictionary <String, QHandle> dict = new LowLevelDictionary <string, QHandle>();

            foreach (QScopeDefinition scope in assembly.AllScopes)
            {
                MetadataReader  reader          = scope.Reader;
                ScopeDefinition scopeDefinition = scope.ScopeDefinition;
                IEnumerable <NamespaceDefinitionHandle> topLevelNamespaceHandles = new NamespaceDefinitionHandle[] { scopeDefinition.RootNamespaceDefinition };
                IEnumerable <NamespaceDefinitionHandle> allNamespaceHandles      = reader.GetTransitiveNamespaces(topLevelNamespaceHandles);
                foreach (NamespaceDefinitionHandle namespaceHandle in allNamespaceHandles)
                {
                    String ns = namespaceHandle.ToNamespaceName(reader);
                    if (ns.Length != 0)
                    {
                        ns = ns + ".";
                    }
                    ns = ns.ToLower();

                    NamespaceDefinition namespaceDefinition = namespaceHandle.GetNamespaceDefinition(reader);
                    foreach (TypeDefinitionHandle typeDefinitionHandle in namespaceDefinition.TypeDefinitions)
                    {
                        String  fullName = ns + typeDefinitionHandle.GetTypeDefinition(reader).Name.GetString(reader).ToLower();
                        QHandle existingValue;
                        if (!dict.TryGetValue(fullName, out existingValue))
                        {
                            dict.Add(fullName, new QHandle(reader, typeDefinitionHandle));
                        }
                    }

                    foreach (TypeForwarderHandle typeForwarderHandle in namespaceDefinition.TypeForwarders)
                    {
                        String  fullName = ns + typeForwarderHandle.GetTypeForwarder(reader).Name.GetString(reader).ToLower();
                        QHandle existingValue;
                        if (!dict.TryGetValue(fullName, out existingValue))
                        {
                            dict.Add(fullName, new QHandle(reader, typeForwarderHandle));
                        }
                    }
                }
            }

            return(dict);
        }
示例#8
0
        //
        // Main routine to resolve a typeDef/Ref/Spec.
        //
        internal static RuntimeType Resolve(this ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeDefRefOrSpec, TypeContext typeContext)
        {
            Exception   exception   = null;
            RuntimeType runtimeType = reflectionDomain.TryResolve(reader, typeDefRefOrSpec, typeContext, ref exception);

            if (runtimeType == null)
            {
                throw exception;
            }
            return(runtimeType);
        }
示例#9
0
文件: Dispensers.cs 项目: rivy/corert
        internal static RuntimeAssembly GetRuntimeAssembly(ReflectionDomain reflectionDomain, RuntimeAssemblyName assemblyRefName)
        {
            RuntimeAssembly result;
            Exception       assemblyLoadException = TryGetRuntimeAssembly(reflectionDomain, assemblyRefName, out result);

            if (assemblyLoadException != null)
            {
                throw assemblyLoadException;
            }
            return(result);
        }
示例#10
0
        public static Object ParseConstantValue(this Handle handle, ReflectionDomain reflectionDomain, MetadataReader reader)
        {
            Object    value;
            Exception exception = handle.TryParseConstantValue(reflectionDomain, reader, out value);

            if (exception != null)
            {
                throw exception;
            }
            return(value);
        }
示例#11
0
        public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
        {
            result = null;
            RuntimeType elementType;
            Exception   typeLoadException = ElementTypeName.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out elementType);

            if (typeLoadException != null)
            {
                return(typeLoadException);
            }
            result = ReflectionCoreNonPortable.GetPointerType(elementType);
            return(null);
        }
示例#12
0
文件: Dispensers.cs 项目: rivy/corert
 internal static Exception TryGetRuntimeAssembly(ReflectionDomain reflectionDomain, RuntimeAssemblyName assemblyRefName, out RuntimeAssembly result)
 {
     Debug.Assert(reflectionDomain == ReflectionCoreExecution.ExecutionDomain, "User Reflection Domains not yet implemented.");
     result = _assemblyRefNameToAssemblyDispenser.GetOrAdd(assemblyRefName);
     if (result != null)
     {
         return(null);
     }
     else
     {
         return(new FileNotFoundException(SR.Format(SR.FileNotFound_AssemblyNotFound, assemblyRefName.FullName)));
     }
 }
示例#13
0
文件: Dispensers.cs 项目: rivy/corert
        public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
        {
            result = _runtimeNamespaceTypeByNameDispenser.GetOrAdd(new NamespaceTypeNameKey(reflectionDomain, currentAssembly, this));
            if (result != null)
            {
                return(null);
            }
            if (!ignoreCase)
            {
                return(new TypeLoadException(SR.Format(SR.TypeLoad_TypeNotFound, this.ToString(), currentAssembly.FullName)));
            }

            return(TryResolveCaseInsensitive(reflectionDomain, currentAssembly, out result));
        }
示例#14
0
        //
        // Returns the ParameterInfo objects for the return parameter (in element 0), and the method parameters (in elements 1..length).
        //
        // The ParameterInfo objects will report "contextMethod" as their Member property and use it to get type variable information from
        // the contextMethod's declaring type. The actual metadata, however, comes from "this."
        //
        // The methodTypeArguments provides the fill-ins for any method type variable elements in the parameter type signatures.
        //
        // Does not array-copy.
        //
        public                                   RuntimeMethodParameterInfo[] GetRuntimeParametersAndReturn(MethodBase contextMethod, RuntimeType[] methodTypeArguments)
        {
            MetadataReader reader      = _reader;
            TypeContext    typeContext = contextMethod.DeclaringType.GetRuntimeTypeInfo <RuntimeTypeInfo>().TypeContext;

            typeContext = new TypeContext(typeContext.GenericTypeArguments, methodTypeArguments);
            ReflectionDomain      reflectionDomain = _definingTypeInfo.ReflectionDomain;
            MethodSignature       methodSignature  = this.MethodSignature;
            LowLevelList <Handle> typeSignatures   = new LowLevelList <Handle>(10);

            typeSignatures.Add(methodSignature.ReturnType.GetReturnTypeSignature(_reader).Type);
            foreach (ParameterTypeSignatureHandle parameterTypeSignatureHandle in methodSignature.Parameters)
            {
                typeSignatures.Add(parameterTypeSignatureHandle.GetParameterTypeSignature(_reader).Type);
            }
            int count = typeSignatures.Count;

            RuntimeMethodParameterInfo[] result = new RuntimeMethodParameterInfo[count];
            foreach (ParameterHandle parameterHandle in _method.Parameters)
            {
                Parameter parameterRecord = parameterHandle.GetParameter(_reader);
                int       index           = parameterRecord.Sequence;
                result[index] =
                    RuntimeFatMethodParameterInfo.GetRuntimeFatMethodParameterInfo(
                        contextMethod,
                        _methodHandle,
                        index - 1,
                        parameterHandle,
                        reflectionDomain,
                        reader,
                        typeSignatures[index],
                        typeContext);
            }
            for (int i = 0; i < count; i++)
            {
                if (result[i] == null)
                {
                    result[i] =
                        RuntimeThinMethodParameterInfo.GetRuntimeThinMethodParameterInfo(
                            contextMethod,
                            i - 1,
                            reflectionDomain,
                            reader,
                            typeSignatures[i],
                            typeContext);
                }
            }
            return(result);
        }
示例#15
0
 public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
 {
     result = null;
     if (AssemblyName == null)
     {
         return TypeName.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out result);
     }
     else
     {
         RuntimeAssembly newAssembly;
         Exception assemblyLoadException = RuntimeAssembly.TryGetRuntimeAssembly(reflectionDomain, AssemblyName, out newAssembly);
         if (assemblyLoadException != null)
             return assemblyLoadException;
         return TypeName.TryResolve(reflectionDomain, newAssembly, ignoreCase, out result);
     }
 }
示例#16
0
        private Exception UncachedTryResolveCaseSensitive(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, out RuntimeType result)
        {
            result = null;

            foreach (QScopeDefinition scopeDefinition in currentAssembly.AllScopes)
            {
                MetadataReader        reader = scopeDefinition.Reader;
                ScopeDefinitionHandle scopeDefinitionHandle = scopeDefinition.Handle;

                NamespaceDefinition namespaceDefinition;
                if (!TryResolveNamespaceDefinitionCaseSensitive(reader, scopeDefinitionHandle, out namespaceDefinition))
                {
                    continue;
                }

                // We've successfully drilled down the namespace chain. Now look for a top-level type matching the type name.
                IEnumerable <TypeDefinitionHandle> candidateTypes = namespaceDefinition.TypeDefinitions;
                foreach (TypeDefinitionHandle candidateType in candidateTypes)
                {
                    TypeDefinition typeDefinition = candidateType.GetTypeDefinition(reader);
                    if (typeDefinition.Name.StringEquals(_name, reader))
                    {
                        result = reflectionDomain.ResolveTypeDefinition(reader, candidateType);
                        return(null);
                    }
                }

                // No match found in this assembly - see if there's a matching type forwarder.
                IEnumerable <TypeForwarderHandle> candidateTypeForwarders = namespaceDefinition.TypeForwarders;
                foreach (TypeForwarderHandle typeForwarderHandle in candidateTypeForwarders)
                {
                    TypeForwarder typeForwarder = typeForwarderHandle.GetTypeForwarder(reader);
                    if (typeForwarder.Name.StringEquals(_name, reader))
                    {
                        RuntimeAssemblyName       redirectedAssemblyName = typeForwarder.Scope.ToRuntimeAssemblyName(reader);
                        AssemblyQualifiedTypeName redirectedTypeName     = new AssemblyQualifiedTypeName(this, redirectedAssemblyName);
                        return(redirectedTypeName.TryResolve(reflectionDomain, null, /*ignoreCase: */ false, out result));
                    }
                }
            }

            {
                String typeName = this.ToString();
                String message  = SR.Format(SR.TypeLoad_TypeNotFound, typeName, currentAssembly.FullName);
                return(ReflectionCoreNonPortable.CreateTypeLoadException(message, typeName));
            }
        }
示例#17
0
        private Exception TryResolveCaseInsensitive(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, out RuntimeType result)
        {
            String fullName = this.ToString().ToLower();

            LowLevelDictionary <String, QHandle> dict = GetCaseInsensitiveTypeDictionary(currentAssembly);
            QHandle qualifiedHandle;

            if (!dict.TryGetValue(fullName, out qualifiedHandle))
            {
                result = null;
                return(new TypeLoadException(SR.Format(SR.TypeLoad_TypeNotFound, this.ToString(), currentAssembly.FullName)));
            }

            MetadataReader reader = qualifiedHandle.Reader;
            Handle         typeDefOrForwarderHandle = qualifiedHandle.Handle;

            HandleType handleType = typeDefOrForwarderHandle.HandleType;

            switch (handleType)
            {
            case HandleType.TypeDefinition:
            {
                TypeDefinitionHandle typeDefinitionHandle = typeDefOrForwarderHandle.ToTypeDefinitionHandle(reader);
                result = reflectionDomain.ResolveTypeDefinition(reader, typeDefinitionHandle);
                return(null);
            }

            case HandleType.TypeForwarder:
            {
                TypeForwarder        typeForwarder           = typeDefOrForwarderHandle.ToTypeForwarderHandle(reader).GetTypeForwarder(reader);
                ScopeReferenceHandle destinationScope        = typeForwarder.Scope;
                RuntimeAssemblyName  destinationAssemblyName = destinationScope.ToRuntimeAssemblyName(reader);
                RuntimeAssembly      destinationAssembly;
                Exception            exception = RuntimeAssembly.TryGetRuntimeAssembly(reflectionDomain, destinationAssemblyName, out destinationAssembly);
                if (exception != null)
                {
                    result = null;
                    return(exception);
                }
                return(TryResolveCaseInsensitive(reflectionDomain, destinationAssembly, out result));
            }

            default:
                throw new InvalidOperationException();
            }
        }
示例#18
0
 public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
 {
     result = null;
     if (AssemblyName == null)
     {
         return(TypeName.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out result));
     }
     else
     {
         RuntimeAssembly newAssembly;
         Exception       assemblyLoadException = RuntimeAssembly.TryGetRuntimeAssembly(reflectionDomain, AssemblyName, out newAssembly);
         if (assemblyLoadException != null)
         {
             return(assemblyLoadException);
         }
         return(TypeName.TryResolve(reflectionDomain, newAssembly, ignoreCase, out result));
     }
 }
示例#19
0
        //
        // This is a port of the desktop CLR's RuntimeType.FormatTypeName() routine. This routine is used by various Reflection ToString() methods
        // to display the name of a type. Do not use for any other purpose as it inherits some pretty quirky desktop behavior.
        //
        // The Project N version takes a raw metadata handle rather than a completed type so that it remains robust in the face of missing metadata.
        //
        public static String FormatTypeName(this RuntimeType runtimeType)
        {
            try
            {
                // Though we wrap this in a try-catch as a failsafe, this code must still strive to avoid triggering MissingMetadata exceptions
                // (non-error exceptions are very annoying when debugging.)

                ReflectionDomain reflectionDomain = runtimeType.GetReflectionDomain();

                // Legacy: this doesn't make sense, why use only Name for nested types but otherwise
                // ToString() which contains namespace.
                RuntimeType rootElementType = runtimeType;
                while (rootElementType.HasElementType)
                {
                    rootElementType = rootElementType.InternalRuntimeElementType;
                }
                if (rootElementType.IsNested)
                {
                    String name = runtimeType.InternalNameIfAvailable;
                    return(name == null ? UnavailableType : name);
                }

                // Legacy: why removing "System"? Is it just because C# has keywords for these types?
                // If so why don't we change it to lower case to match the C# keyword casing?
                FoundationTypes foundationTypes = reflectionDomain.FoundationTypes;
                String          typeName        = runtimeType.ToString();
                if (typeName.StartsWith("System."))
                {
                    foreach (Type pt in reflectionDomain.PrimitiveTypes)
                    {
                        if (pt.Equals(rootElementType) || rootElementType.Equals(foundationTypes.SystemVoid))
                        {
                            typeName = typeName.Substring("System.".Length);
                            break;
                        }
                    }
                }
                return(typeName);
            }
            catch (Exception)
            {
                return(UnavailableType);
            }
        }
示例#20
0
        public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
        {
            result = null;
            RuntimeType declaringType;
            Exception   typeLoadException = DeclaringType.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out declaringType);

            if (typeLoadException != null)
            {
                return(typeLoadException);
            }
            TypeInfo nestedTypeInfo = FindDeclaredNestedType(declaringType.GetTypeInfo(), Name, ignoreCase);

            if (nestedTypeInfo == null)
            {
                return(new TypeLoadException(SR.Format(SR.TypeLoad_TypeNotFound, declaringType.FullName + "+" + Name, currentAssembly.FullName)));
            }
            result = (RuntimeType)(nestedTypeInfo.AsType());
            return(null);
        }
示例#21
0
        internal static RuntimeType TryResolve(this ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeDefRefOrSpec, TypeContext typeContext, ref Exception exception)
        {
            HandleType handleType = typeDefRefOrSpec.HandleType;

            if (handleType == HandleType.TypeDefinition)
            {
                return(reflectionDomain.ResolveTypeDefinition(reader, typeDefRefOrSpec.ToTypeDefinitionHandle(reader)));
            }
            else if (handleType == HandleType.TypeReference)
            {
                return(reflectionDomain.TryResolveTypeReference(reader, typeDefRefOrSpec.ToTypeReferenceHandle(reader), ref exception));
            }
            else if (handleType == HandleType.TypeSpecification)
            {
                return(reflectionDomain.TryResolveTypeSignature(reader, typeDefRefOrSpec.ToTypeSpecificationHandle(reader), typeContext, ref exception));
            }
            else
            {
                throw new BadImageFormatException();  // Expected TypeRef, Def or Spec.
            }
        }
示例#22
0
        // 
        // This is a port of the desktop CLR's RuntimeType.FormatTypeName() routine. This routine is used by various Reflection ToString() methods
        // to display the name of a type. Do not use for any other purpose as it inherits some pretty quirky desktop behavior.
        //
        // The Project N version takes a raw metadata handle rather than a completed type so that it remains robust in the face of missing metadata.
        //
        public static String FormatTypeName(this Handle typeDefRefOrSpecHandle, MetadataReader reader, TypeContext typeContext, ReflectionDomain reflectionDomain)
        {
            try
            {
                // Though we wrap this in a try-catch as a failsafe, this code must still strive to avoid triggering MissingMetadata exceptions
                // (non-error exceptions are very annoying when debugging.)

                Exception exception = null;
                RuntimeType runtimeType = reflectionDomain.TryResolve(reader, typeDefRefOrSpecHandle, typeContext, ref exception);
                if (runtimeType == null)
                    return UnavailableType;

                // Because this runtimeType came from a successful TryResolve() call, it is safe to querying the TypeInfo's of the type and its component parts.
                // If we're wrong, we do have the safety net of a try-catch.
                return runtimeType.FormatTypeName();
            }
            catch (Exception)
            {
                return UnavailableType;
            }
        }
示例#23
0
文件: Dispensers.cs 项目: rivy/corert
 private static CustomAttributeData GetCustomAttributeData(ReflectionDomain reflectionDomain, MetadataReader reader, CustomAttributeHandle customAttributeHandle)
 {
     return(new RuntimeNormalCustomAttributeData(reflectionDomain, reader, customAttributeHandle));
 }
 public static Object ParseConstantValue(this Handle handle, ReflectionDomain reflectionDomain, MetadataReader reader)
 {
     Object value;
     Exception exception = handle.TryParseConstantValue(reflectionDomain, reader, out value);
     if (exception != null)
         throw exception;
     return value;
 }
 public static Exception TryParseConstantValue(this Handle handle, ReflectionDomain reflectionDomain, MetadataReader reader, out Object value)
 {
     HandleType handleType = handle.HandleType;
     switch (handleType)
     {
         case HandleType.ConstantBooleanValue:
             value = handle.ToConstantBooleanValueHandle(reader).GetConstantBooleanValue(reader).Value;
             return null;
         case HandleType.ConstantStringValue:
             value = handle.ToConstantStringValueHandle(reader).GetConstantStringValue(reader).Value;
             return null;
         case HandleType.ConstantCharValue:
             value = handle.ToConstantCharValueHandle(reader).GetConstantCharValue(reader).Value;
             return null;
         case HandleType.ConstantByteValue:
             value = handle.ToConstantByteValueHandle(reader).GetConstantByteValue(reader).Value;
             return null;
         case HandleType.ConstantSByteValue:
             value = handle.ToConstantSByteValueHandle(reader).GetConstantSByteValue(reader).Value;
             return null;
         case HandleType.ConstantInt16Value:
             value = handle.ToConstantInt16ValueHandle(reader).GetConstantInt16Value(reader).Value;
             return null;
         case HandleType.ConstantUInt16Value:
             value = handle.ToConstantUInt16ValueHandle(reader).GetConstantUInt16Value(reader).Value;
             return null;
         case HandleType.ConstantInt32Value:
             value = handle.ToConstantInt32ValueHandle(reader).GetConstantInt32Value(reader).Value;
             return null;
         case HandleType.ConstantUInt32Value:
             value = handle.ToConstantUInt32ValueHandle(reader).GetConstantUInt32Value(reader).Value;
             return null;
         case HandleType.ConstantInt64Value:
             value = handle.ToConstantInt64ValueHandle(reader).GetConstantInt64Value(reader).Value;
             return null;
         case HandleType.ConstantUInt64Value:
             value = handle.ToConstantUInt64ValueHandle(reader).GetConstantUInt64Value(reader).Value;
             return null;
         case HandleType.ConstantSingleValue:
             value = handle.ToConstantSingleValueHandle(reader).GetConstantSingleValue(reader).Value;
             return null;
         case HandleType.ConstantDoubleValue:
             value = handle.ToConstantDoubleValueHandle(reader).GetConstantDoubleValue(reader).Value;
             return null;
         case HandleType.TypeDefinition:
         case HandleType.TypeReference:
         case HandleType.TypeSpecification:
             {
                 Exception exception = null;
                 value = reflectionDomain.TryResolve(reader, handle, new TypeContext(null, null), ref exception);
                 return (value == null) ? exception : null;
             }
         case HandleType.ConstantReferenceValue:
             value = null;
             return null;
         case HandleType.ConstantBoxedEnumValue:
             {
                 return handle.ToConstantBoxedEnumValueHandle(reader).ParseBoxedEnumConstantValue(reflectionDomain, reader, out value);
             }
         default:
             {
                 Exception exception;
                 value = handle.TryParseConstantArray(reflectionDomain, reader, out exception);
                 if (value == null)
                     return exception;
                 return null;
             }
     }
 }
示例#26
0
文件: Dispensers.cs 项目: rivy/corert
 internal static RuntimeFatMethodParameterInfo GetRuntimeFatMethodParameterInfo(MethodBase member, MethodHandle methodHandle, int position, ParameterHandle parameterHandle, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
 {
     return(new RuntimeFatMethodParameterInfo(member, methodHandle, position, parameterHandle, reflectionDomain, reader, typeHandle, typeContext));
 }
        public static IEnumerable TryParseConstantArray(this Handle handle, ReflectionDomain reflectionDomain, MetadataReader reader, out Exception exception)
        {
            exception = null;

            HandleType handleType = handle.HandleType;
            switch (handleType)
            {
                case HandleType.ConstantBooleanArray:
                    return handle.ToConstantBooleanArrayHandle(reader).GetConstantBooleanArray(reader).Value;

                case HandleType.ConstantStringArray:
                    return handle.ToConstantStringArrayHandle(reader).GetConstantStringArray(reader).Value;

                case HandleType.ConstantCharArray:
                    return handle.ToConstantCharArrayHandle(reader).GetConstantCharArray(reader).Value;

                case HandleType.ConstantByteArray:
                    return handle.ToConstantByteArrayHandle(reader).GetConstantByteArray(reader).Value;

                case HandleType.ConstantSByteArray:
                    return handle.ToConstantSByteArrayHandle(reader).GetConstantSByteArray(reader).Value;

                case HandleType.ConstantInt16Array:
                    return handle.ToConstantInt16ArrayHandle(reader).GetConstantInt16Array(reader).Value;

                case HandleType.ConstantUInt16Array:
                    return handle.ToConstantUInt16ArrayHandle(reader).GetConstantUInt16Array(reader).Value;

                case HandleType.ConstantInt32Array:
                    return handle.ToConstantInt32ArrayHandle(reader).GetConstantInt32Array(reader).Value;

                case HandleType.ConstantUInt32Array:
                    return handle.ToConstantUInt32ArrayHandle(reader).GetConstantUInt32Array(reader).Value;

                case HandleType.ConstantInt64Array:
                    return handle.ToConstantInt64ArrayHandle(reader).GetConstantInt64Array(reader).Value;

                case HandleType.ConstantUInt64Array:
                    return handle.ToConstantUInt64ArrayHandle(reader).GetConstantUInt64Array(reader).Value;

                case HandleType.ConstantSingleArray:
                    return handle.ToConstantSingleArrayHandle(reader).GetConstantSingleArray(reader).Value;

                case HandleType.ConstantDoubleArray:
                    return handle.ToConstantDoubleArrayHandle(reader).GetConstantDoubleArray(reader).Value;

                case HandleType.ConstantHandleArray:
                    {
                        Handle[] constantHandles = handle.ToConstantHandleArrayHandle(reader).GetConstantHandleArray(reader).Value.ToArray();
                        object[] elements = new object[constantHandles.Length];
                        for (int i = 0; i < constantHandles.Length; i++)
                        {
                            exception = constantHandles[i].TryParseConstantValue(reflectionDomain, reader, out elements[i]);
                            if (exception != null)
                                return null;
                        }
                        return elements;
                    }
                default:
                    throw new BadImageFormatException();
            }
        }
示例#28
0
文件: Dispensers.cs 项目: rivy/corert
 private static RuntimeAssembly GetRuntimeAssembly(MetadataReader reader, ScopeDefinitionHandle scope, IEnumerable <QScopeDefinition> overflows, ReflectionDomain reflectionDomain)
 {
     return(_scopeToAssemblyDispenser.GetOrAdd(new RuntimeAssemblyKey(reader, scope, overflows)));
 }
示例#29
0
 public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
 {
     result = null;
     RuntimeType genericType;
     Exception typeLoadException = GenericType.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out genericType);
     if (typeLoadException != null)
         return typeLoadException;
     LowLevelList<RuntimeType> genericTypeArguments = new LowLevelList<RuntimeType>();
     foreach (TypeName genericTypeArgumentName in GenericArguments)
     {
         RuntimeType genericTypeArgument;
         typeLoadException = genericTypeArgumentName.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out genericTypeArgument);
         if (typeLoadException != null)
             return typeLoadException;
         genericTypeArguments.Add(genericTypeArgument);
     }
     result = ReflectionCoreNonPortable.GetConstructedGenericType(genericType, genericTypeArguments.ToArray());
     return null;
 }
示例#30
0
 public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
 {
     result = null;
     RuntimeType declaringType;
     Exception typeLoadException = DeclaringType.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out declaringType);
     if (typeLoadException != null)
         return typeLoadException;
     TypeInfo nestedTypeInfo = FindDeclaredNestedType(declaringType.GetTypeInfo(), Name, ignoreCase);
     if (nestedTypeInfo == null)
         return new TypeLoadException(SR.Format(SR.TypeLoad_TypeNotFound, declaringType.FullName + "+" + Name, currentAssembly.FullName));
     result = (RuntimeType)(nestedTypeInfo.AsType());
     return null;
 }
示例#31
0
 public sealed override Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result)
 {
     result = null;
     RuntimeType elementType;
     Exception typeLoadException = ElementTypeName.TryResolve(reflectionDomain, currentAssembly, ignoreCase, out elementType);
     if (typeLoadException != null)
         return typeLoadException;
     result = ReflectionCoreNonPortable.GetPointerType(elementType);
     return null;
 }
示例#32
0
 public abstract Exception TryResolve(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, bool ignoreCase, out RuntimeType result);
示例#33
0
 //
 // Main routine to resolve a typeDefinition.
 //
 internal static RuntimeType ResolveTypeDefinition(this ReflectionDomain reflectionDomain, MetadataReader reader, TypeDefinitionHandle typeDefinitionHandle)
 {
     return(RuntimeTypeUnifierEx.GetNamedType(reader, typeDefinitionHandle));
 }
示例#34
0
        //
        // Main routine to parse a metadata type specification signature.
        //
        private static RuntimeType TryResolveTypeSignature(this ReflectionDomain reflectionDomain, MetadataReader reader, TypeSpecificationHandle typeSpecHandle, TypeContext typeContext, ref Exception exception)
        {
            Handle typeHandle = typeSpecHandle.GetTypeSpecification(reader).Signature;

            switch (typeHandle.HandleType)
            {
            case HandleType.ArraySignature:
            {
                ArraySignature sig  = typeHandle.ToArraySignatureHandle(reader).GetArraySignature(reader);
                int            rank = sig.Rank;
                if (rank <= 0)
                {
                    throw new BadImageFormatException();         // Bad rank.
                }
                RuntimeType elementType = reflectionDomain.TryResolve(reader, sig.ElementType, typeContext, ref exception);
                if (elementType == null)
                {
                    return(null);
                }
                return(ReflectionCoreNonPortable.GetMultiDimArrayType(elementType, rank));
            }

            case HandleType.ByReferenceSignature:
            {
                ByReferenceSignature sig        = typeHandle.ToByReferenceSignatureHandle(reader).GetByReferenceSignature(reader);
                RuntimeType          targetType = reflectionDomain.TryResolve(reader, sig.Type, typeContext, ref exception);
                if (targetType == null)
                {
                    return(null);
                }
                return(ReflectionCoreNonPortable.GetByRefType(targetType));
            }

            case HandleType.MethodTypeVariableSignature:
            {
                MethodTypeVariableSignature sig = typeHandle.ToMethodTypeVariableSignatureHandle(reader).GetMethodTypeVariableSignature(reader);
                return(typeContext.GenericMethodArguments[sig.Number]);
            }

            case HandleType.PointerSignature:
            {
                PointerSignature sig        = typeHandle.ToPointerSignatureHandle(reader).GetPointerSignature(reader);
                RuntimeType      targetType = reflectionDomain.TryResolve(reader, sig.Type, typeContext, ref exception);
                if (targetType == null)
                {
                    return(null);
                }
                return(ReflectionCoreNonPortable.GetPointerType(targetType));
            }

            case HandleType.SZArraySignature:
            {
                SZArraySignature sig         = typeHandle.ToSZArraySignatureHandle(reader).GetSZArraySignature(reader);
                RuntimeType      elementType = reflectionDomain.TryResolve(reader, sig.ElementType, typeContext, ref exception);
                if (elementType == null)
                {
                    return(null);
                }
                return(ReflectionCoreNonPortable.GetArrayType(elementType));
            }

            case HandleType.TypeDefinition:
            {
                return(reflectionDomain.ResolveTypeDefinition(reader, typeHandle.ToTypeDefinitionHandle(reader)));
            }

            case HandleType.TypeInstantiationSignature:
            {
                TypeInstantiationSignature sig    = typeHandle.ToTypeInstantiationSignatureHandle(reader).GetTypeInstantiationSignature(reader);
                RuntimeType genericTypeDefinition = reflectionDomain.TryResolve(reader, sig.GenericType, typeContext, ref exception);
                if (genericTypeDefinition == null)
                {
                    return(null);
                }
                LowLevelList <RuntimeType> genericTypeArguments = new LowLevelList <RuntimeType>();
                foreach (Handle genericTypeArgumentHandle in sig.GenericTypeArguments)
                {
                    RuntimeType genericTypeArgument = reflectionDomain.TryResolve(reader, genericTypeArgumentHandle, typeContext, ref exception);
                    if (genericTypeArgument == null)
                    {
                        return(null);
                    }
                    genericTypeArguments.Add(genericTypeArgument);
                }
                return(ReflectionCoreNonPortable.GetConstructedGenericType(genericTypeDefinition, genericTypeArguments.ToArray()));
            }

            case HandleType.TypeReference:
            {
                return(reflectionDomain.TryResolveTypeReference(reader, typeHandle.ToTypeReferenceHandle(reader), ref exception));
            }

            case HandleType.TypeVariableSignature:
            {
                TypeVariableSignature sig = typeHandle.ToTypeVariableSignatureHandle(reader).GetTypeVariableSignature(reader);
                return(typeContext.GenericTypeArguments[sig.Number]);
            }

            default:
                throw new NotSupportedException();     // Unexpected Type signature type.
            }
        }
        private static Exception ParseBoxedEnumConstantValue(this ConstantBoxedEnumValueHandle handle, ReflectionDomain reflectionDomain, MetadataReader reader, out Object value)
        {
            if (!(reflectionDomain is Internal.Reflection.Core.Execution.ExecutionDomain))
                throw new PlatformNotSupportedException(); // Cannot work because boxing enums won't work in non-execution domains.

            ConstantBoxedEnumValue record = handle.GetConstantBoxedEnumValue(reader);

            Exception exception = null;
            Type enumType = reflectionDomain.TryResolve(reader, record.Type, new TypeContext(null, null), ref exception);
            if (enumType == null)
            {
                value = null;
                return exception;
            }

            if (!enumType.GetTypeInfo().IsEnum)
                throw new BadImageFormatException();

            Type underlyingType = Enum.GetUnderlyingType(enumType);

            // Now box the value as the specified enum type.
            unsafe
            {
                switch (record.Value.HandleType)
                {
                    case HandleType.ConstantByteValue:
                        {
                            if (underlyingType != typeof(byte))
                                throw new BadImageFormatException();

                            byte v = record.Value.ToConstantByteValueHandle(reader).GetConstantByteValue(reader).Value;
                            value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                            return null;
                        }
                    case HandleType.ConstantSByteValue:
                        {
                            if (underlyingType != typeof(sbyte))
                                throw new BadImageFormatException();

                            sbyte v = record.Value.ToConstantSByteValueHandle(reader).GetConstantSByteValue(reader).Value;
                            value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                            return null;
                        }
                    case HandleType.ConstantInt16Value:
                        {
                            if (underlyingType != typeof(short))
                                throw new BadImageFormatException();

                            short v = record.Value.ToConstantInt16ValueHandle(reader).GetConstantInt16Value(reader).Value;
                            value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                            return null;
                        }
                    case HandleType.ConstantUInt16Value:
                        {
                            if (underlyingType != typeof(ushort))
                                throw new BadImageFormatException();

                            ushort v = record.Value.ToConstantUInt16ValueHandle(reader).GetConstantUInt16Value(reader).Value;
                            value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                            return null;
                        }
                    case HandleType.ConstantInt32Value:
                        {
                            if (underlyingType != typeof(int))
                                throw new BadImageFormatException();

                            int v = record.Value.ToConstantInt32ValueHandle(reader).GetConstantInt32Value(reader).Value;
                            value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                            return null;
                        }
                    case HandleType.ConstantUInt32Value:
                        {
                            if (underlyingType != typeof(uint))
                                throw new BadImageFormatException();

                            uint v = record.Value.ToConstantUInt32ValueHandle(reader).GetConstantUInt32Value(reader).Value;
                            value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                            return null;
                        }
                    case HandleType.ConstantInt64Value:
                        {
                            if (underlyingType != typeof(long))
                                throw new BadImageFormatException();

                            long v = record.Value.ToConstantInt64ValueHandle(reader).GetConstantInt64Value(reader).Value;
                            value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                            return null;
                        }
                    case HandleType.ConstantUInt64Value:
                        {
                            if (underlyingType != typeof(ulong))
                                throw new BadImageFormatException();

                            ulong v = record.Value.ToConstantUInt64ValueHandle(reader).GetConstantUInt64Value(reader).Value;
                            value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                            return null;
                        }
                    default:
                        throw new BadImageFormatException();
                }
            }

        }
示例#36
0
        //
        // Main routine to resolve a typeReference.
        //
        private static RuntimeType TryResolveTypeReference(this ReflectionDomain reflectionDomain, MetadataReader reader, TypeReferenceHandle typeReferenceHandle, ref Exception exception)
        {
            {
                ExecutionDomain executionDomain = reflectionDomain as ExecutionDomain;
                if (executionDomain != null)
                {
                    RuntimeTypeHandle resolvedRuntimeTypeHandle;
                    if (executionDomain.ExecutionEnvironment.TryGetNamedTypeForTypeReference(reader, typeReferenceHandle, out resolvedRuntimeTypeHandle))
                    {
                        return(ReflectionCoreNonPortable.GetTypeForRuntimeTypeHandle(resolvedRuntimeTypeHandle));
                    }
                }
            }

            TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader);
            String        name          = typeReference.TypeName.GetString(reader);
            Handle        parent        = typeReference.ParentNamespaceOrType;
            HandleType    parentType    = parent.HandleType;
            TypeInfo      outerTypeInfo = null;

            // Check if this is a reference to a nested type.

            if (parentType == HandleType.TypeDefinition)
            {
                outerTypeInfo = RuntimeNamedTypeInfo.GetRuntimeNamedTypeInfo(reader, parent.ToTypeDefinitionHandle(reader));
            }
            else if (parentType == HandleType.TypeReference)
            {
                RuntimeType outerType = reflectionDomain.TryResolveTypeReference(reader, parent.ToTypeReferenceHandle(reader), ref exception);
                if (outerType == null)
                {
                    return(null);
                }
                outerTypeInfo = outerType.GetTypeInfo();   // Since we got to outerType via a metadata reference, we're assured GetTypeInfo() won't throw a MissingMetadataException.
            }
            if (outerTypeInfo != null)
            {
                // It was a nested type. We've already resolved the containing type recursively - just find the nested among its direct children.
                TypeInfo resolvedTypeInfo = outerTypeInfo.GetDeclaredNestedType(name);
                if (resolvedTypeInfo == null)
                {
                    exception = reflectionDomain.CreateMissingMetadataException(outerTypeInfo, name);
                    return(null);
                }
                return((RuntimeType)(resolvedTypeInfo.AsType()));
            }


            // If we got here, the typeReference was to a non-nested type.
            if (parentType == HandleType.NamespaceReference)
            {
                AssemblyQualifiedTypeName assemblyQualifiedTypeName = parent.ToNamespaceReferenceHandle(reader).ToAssemblyQualifiedTypeName(name, reader);
                RuntimeType runtimeType;
                exception = assemblyQualifiedTypeName.TryResolve(reflectionDomain, null, /*ignoreCase: */ false, out runtimeType);
                if (exception != null)
                {
                    return(null);
                }
                return(runtimeType);
            }

            throw new BadImageFormatException(); // Expected TypeReference parent to be typeRef, typeDef or namespaceRef.
        }
示例#37
0
文件: Dispensers.cs 项目: rivy/corert
 public NamespaceTypeNameKey(ReflectionDomain reflectionDomain, RuntimeAssembly runtimeAssembly, NamespaceTypeName namespaceTypeName)
 {
     _reflectionDomain  = reflectionDomain;
     _runtimeAssembly   = runtimeAssembly;
     _namespaceTypeName = namespaceTypeName;
 }
 private RuntimeThinMethodParameterInfo(MethodBase member, int position, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
     : base(member, position, reflectionDomain, reader, typeHandle, typeContext)
 {
 }
 internal RuntimeNormalCustomAttributeData(ReflectionDomain reflectionDomain, MetadataReader reader, CustomAttributeHandle customAttributeHandle)
 {
     _reflectionDomain = reflectionDomain;
     _reader = reader;
     _customAttribute = customAttributeHandle.GetCustomAttribute(reader);
 }
示例#40
0
        public static IEnumerable TryParseConstantArray(this Handle handle, ReflectionDomain reflectionDomain, MetadataReader reader, out Exception exception)
        {
            exception = null;

            HandleType handleType = handle.HandleType;

            switch (handleType)
            {
            case HandleType.ConstantBooleanArray:
                return(handle.ToConstantBooleanArrayHandle(reader).GetConstantBooleanArray(reader).Value);

            case HandleType.ConstantStringArray:
                return(handle.ToConstantStringArrayHandle(reader).GetConstantStringArray(reader).Value);

            case HandleType.ConstantCharArray:
                return(handle.ToConstantCharArrayHandle(reader).GetConstantCharArray(reader).Value);

            case HandleType.ConstantByteArray:
                return(handle.ToConstantByteArrayHandle(reader).GetConstantByteArray(reader).Value);

            case HandleType.ConstantSByteArray:
                return(handle.ToConstantSByteArrayHandle(reader).GetConstantSByteArray(reader).Value);

            case HandleType.ConstantInt16Array:
                return(handle.ToConstantInt16ArrayHandle(reader).GetConstantInt16Array(reader).Value);

            case HandleType.ConstantUInt16Array:
                return(handle.ToConstantUInt16ArrayHandle(reader).GetConstantUInt16Array(reader).Value);

            case HandleType.ConstantInt32Array:
                return(handle.ToConstantInt32ArrayHandle(reader).GetConstantInt32Array(reader).Value);

            case HandleType.ConstantUInt32Array:
                return(handle.ToConstantUInt32ArrayHandle(reader).GetConstantUInt32Array(reader).Value);

            case HandleType.ConstantInt64Array:
                return(handle.ToConstantInt64ArrayHandle(reader).GetConstantInt64Array(reader).Value);

            case HandleType.ConstantUInt64Array:
                return(handle.ToConstantUInt64ArrayHandle(reader).GetConstantUInt64Array(reader).Value);

            case HandleType.ConstantSingleArray:
                return(handle.ToConstantSingleArrayHandle(reader).GetConstantSingleArray(reader).Value);

            case HandleType.ConstantDoubleArray:
                return(handle.ToConstantDoubleArrayHandle(reader).GetConstantDoubleArray(reader).Value);

            case HandleType.ConstantHandleArray:
            {
                Handle[] constantHandles = handle.ToConstantHandleArrayHandle(reader).GetConstantHandleArray(reader).Value.ToArray();
                object[] elements        = new object[constantHandles.Length];
                for (int i = 0; i < constantHandles.Length; i++)
                {
                    exception = constantHandles[i].TryParseConstantValue(reflectionDomain, reader, out elements[i]);
                    if (exception != null)
                    {
                        return(null);
                    }
                }
                return(elements);
            }

            default:
                throw new BadImageFormatException();
            }
        }
示例#41
0
        private static Exception ParseBoxedEnumConstantValue(this ConstantBoxedEnumValueHandle handle, ReflectionDomain reflectionDomain, MetadataReader reader, out Object value)
        {
            if (!(reflectionDomain is Internal.Reflection.Core.Execution.ExecutionDomain))
            {
                throw new PlatformNotSupportedException(); // Cannot work because boxing enums won't work in non-execution domains.
            }
            ConstantBoxedEnumValue record = handle.GetConstantBoxedEnumValue(reader);

            Exception exception = null;
            Type      enumType  = reflectionDomain.TryResolve(reader, record.Type, new TypeContext(null, null), ref exception);

            if (enumType == null)
            {
                value = null;
                return(exception);
            }

            if (!enumType.GetTypeInfo().IsEnum)
            {
                throw new BadImageFormatException();
            }

            Type underlyingType = Enum.GetUnderlyingType(enumType);

            // Now box the value as the specified enum type.
            unsafe
            {
                switch (record.Value.HandleType)
                {
                case HandleType.ConstantByteValue:
                {
                    if (underlyingType != typeof(byte))
                    {
                        throw new BadImageFormatException();
                    }

                    byte v = record.Value.ToConstantByteValueHandle(reader).GetConstantByteValue(reader).Value;
                    value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                    return(null);
                }

                case HandleType.ConstantSByteValue:
                {
                    if (underlyingType != typeof(sbyte))
                    {
                        throw new BadImageFormatException();
                    }

                    sbyte v = record.Value.ToConstantSByteValueHandle(reader).GetConstantSByteValue(reader).Value;
                    value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                    return(null);
                }

                case HandleType.ConstantInt16Value:
                {
                    if (underlyingType != typeof(short))
                    {
                        throw new BadImageFormatException();
                    }

                    short v = record.Value.ToConstantInt16ValueHandle(reader).GetConstantInt16Value(reader).Value;
                    value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                    return(null);
                }

                case HandleType.ConstantUInt16Value:
                {
                    if (underlyingType != typeof(ushort))
                    {
                        throw new BadImageFormatException();
                    }

                    ushort v = record.Value.ToConstantUInt16ValueHandle(reader).GetConstantUInt16Value(reader).Value;
                    value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                    return(null);
                }

                case HandleType.ConstantInt32Value:
                {
                    if (underlyingType != typeof(int))
                    {
                        throw new BadImageFormatException();
                    }

                    int v = record.Value.ToConstantInt32ValueHandle(reader).GetConstantInt32Value(reader).Value;
                    value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                    return(null);
                }

                case HandleType.ConstantUInt32Value:
                {
                    if (underlyingType != typeof(uint))
                    {
                        throw new BadImageFormatException();
                    }

                    uint v = record.Value.ToConstantUInt32ValueHandle(reader).GetConstantUInt32Value(reader).Value;
                    value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                    return(null);
                }

                case HandleType.ConstantInt64Value:
                {
                    if (underlyingType != typeof(long))
                    {
                        throw new BadImageFormatException();
                    }

                    long v = record.Value.ToConstantInt64ValueHandle(reader).GetConstantInt64Value(reader).Value;
                    value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                    return(null);
                }

                case HandleType.ConstantUInt64Value:
                {
                    if (underlyingType != typeof(ulong))
                    {
                        throw new BadImageFormatException();
                    }

                    ulong v = record.Value.ToConstantUInt64ValueHandle(reader).GetConstantUInt64Value(reader).Value;
                    value = RuntimeAugments.Box(enumType.TypeHandle, (IntPtr)(&v));
                    return(null);
                }

                default:
                    throw new BadImageFormatException();
                }
            }
        }
示例#42
0
 private RuntimeFatMethodParameterInfo(MethodBase member, MethodHandle methodHandle, int position, ParameterHandle parameterHandle, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
     : base(member, position, reflectionDomain, reader, typeHandle, typeContext)
 {
     _methodHandle    = methodHandle;
     _parameterHandle = parameterHandle;
     _parameter       = parameterHandle.GetParameter(reader);
 }
示例#43
0
        public static Exception TryParseConstantValue(this Handle handle, ReflectionDomain reflectionDomain, MetadataReader reader, out Object value)
        {
            HandleType handleType = handle.HandleType;

            switch (handleType)
            {
            case HandleType.ConstantBooleanValue:
                value = handle.ToConstantBooleanValueHandle(reader).GetConstantBooleanValue(reader).Value;
                return(null);

            case HandleType.ConstantStringValue:
                value = handle.ToConstantStringValueHandle(reader).GetConstantStringValue(reader).Value;
                return(null);

            case HandleType.ConstantCharValue:
                value = handle.ToConstantCharValueHandle(reader).GetConstantCharValue(reader).Value;
                return(null);

            case HandleType.ConstantByteValue:
                value = handle.ToConstantByteValueHandle(reader).GetConstantByteValue(reader).Value;
                return(null);

            case HandleType.ConstantSByteValue:
                value = handle.ToConstantSByteValueHandle(reader).GetConstantSByteValue(reader).Value;
                return(null);

            case HandleType.ConstantInt16Value:
                value = handle.ToConstantInt16ValueHandle(reader).GetConstantInt16Value(reader).Value;
                return(null);

            case HandleType.ConstantUInt16Value:
                value = handle.ToConstantUInt16ValueHandle(reader).GetConstantUInt16Value(reader).Value;
                return(null);

            case HandleType.ConstantInt32Value:
                value = handle.ToConstantInt32ValueHandle(reader).GetConstantInt32Value(reader).Value;
                return(null);

            case HandleType.ConstantUInt32Value:
                value = handle.ToConstantUInt32ValueHandle(reader).GetConstantUInt32Value(reader).Value;
                return(null);

            case HandleType.ConstantInt64Value:
                value = handle.ToConstantInt64ValueHandle(reader).GetConstantInt64Value(reader).Value;
                return(null);

            case HandleType.ConstantUInt64Value:
                value = handle.ToConstantUInt64ValueHandle(reader).GetConstantUInt64Value(reader).Value;
                return(null);

            case HandleType.ConstantSingleValue:
                value = handle.ToConstantSingleValueHandle(reader).GetConstantSingleValue(reader).Value;
                return(null);

            case HandleType.ConstantDoubleValue:
                value = handle.ToConstantDoubleValueHandle(reader).GetConstantDoubleValue(reader).Value;
                return(null);

            case HandleType.TypeDefinition:
            case HandleType.TypeReference:
            case HandleType.TypeSpecification:
            {
                Exception exception = null;
                value = reflectionDomain.TryResolve(reader, handle, new TypeContext(null, null), ref exception);
                return((value == null) ? exception : null);
            }

            case HandleType.ConstantReferenceValue:
                value = null;
                return(null);

            case HandleType.ConstantBoxedEnumValue:
            {
                return(handle.ToConstantBoxedEnumValueHandle(reader).ParseBoxedEnumConstantValue(reflectionDomain, reader, out value));
            }

            default:
            {
                Exception exception;
                value = handle.TryParseConstantArray(reflectionDomain, reader, out exception);
                if (value == null)
                {
                    return(exception);
                }
                return(null);
            }
            }
        }
示例#44
0
        private Exception UncachedTryResolveCaseSensitive(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, out RuntimeType result)
        {
            result = null;

            foreach (QScopeDefinition scopeDefinition in currentAssembly.AllScopes)
            {
                MetadataReader reader = scopeDefinition.Reader;
                ScopeDefinitionHandle scopeDefinitionHandle = scopeDefinition.Handle;

                NamespaceDefinition namespaceDefinition;
                if (!TryResolveNamespaceDefinitionCaseSensitive(reader, scopeDefinitionHandle, out namespaceDefinition))
                {
                    continue;
                }

                // We've successfully drilled down the namespace chain. Now look for a top-level type matching the type name.
                IEnumerable<TypeDefinitionHandle> candidateTypes = namespaceDefinition.TypeDefinitions;
                foreach (TypeDefinitionHandle candidateType in candidateTypes)
                {
                    TypeDefinition typeDefinition = candidateType.GetTypeDefinition(reader);
                    if (typeDefinition.Name.StringEquals(_name, reader))
                    {
                        result = reflectionDomain.ResolveTypeDefinition(reader, candidateType);
                        return null;
                    }
                }

                // No match found in this assembly - see if there's a matching type forwarder.
                IEnumerable<TypeForwarderHandle> candidateTypeForwarders = namespaceDefinition.TypeForwarders;
                foreach (TypeForwarderHandle typeForwarderHandle in candidateTypeForwarders)
                {
                    TypeForwarder typeForwarder = typeForwarderHandle.GetTypeForwarder(reader);
                    if (typeForwarder.Name.StringEquals(_name, reader))
                    {
                        RuntimeAssemblyName redirectedAssemblyName = typeForwarder.Scope.ToRuntimeAssemblyName(reader);
                        AssemblyQualifiedTypeName redirectedTypeName = new AssemblyQualifiedTypeName(this, redirectedAssemblyName);
                        return redirectedTypeName.TryResolve(reflectionDomain, null, /*ignoreCase: */false, out result);
                    }
                }
            }

            {
                String typeName = this.ToString();
                String message = SR.Format(SR.TypeLoad_TypeNotFound, typeName, currentAssembly.FullName);
                return ReflectionCoreNonPortable.CreateTypeLoadException(message, typeName);
            }
        }
 private RuntimeThinMethodParameterInfo(MethodBase member, int position, ReflectionDomain reflectionDomain, MetadataReader reader, Handle typeHandle, TypeContext typeContext)
     : base(member, position, reflectionDomain, reader, typeHandle, typeContext)
 {
 }
示例#46
0
        private Exception TryResolveCaseInsensitive(ReflectionDomain reflectionDomain, RuntimeAssembly currentAssembly, out RuntimeType result)
        {
            String fullName = this.ToString().ToLower();

            LowLevelDictionary<String, QHandle> dict = GetCaseInsensitiveTypeDictionary(currentAssembly);
            QHandle qualifiedHandle;
            if (!dict.TryGetValue(fullName, out qualifiedHandle))
            {
                result = null;
                return new TypeLoadException(SR.Format(SR.TypeLoad_TypeNotFound, this.ToString(), currentAssembly.FullName));
            }

            MetadataReader reader = qualifiedHandle.Reader;
            Handle typeDefOrForwarderHandle = qualifiedHandle.Handle;

            HandleType handleType = typeDefOrForwarderHandle.HandleType;
            switch (handleType)
            {
                case HandleType.TypeDefinition:
                    {
                        TypeDefinitionHandle typeDefinitionHandle = typeDefOrForwarderHandle.ToTypeDefinitionHandle(reader);
                        result = reflectionDomain.ResolveTypeDefinition(reader, typeDefinitionHandle);
                        return null;
                    }
                case HandleType.TypeForwarder:
                    {
                        TypeForwarder typeForwarder = typeDefOrForwarderHandle.ToTypeForwarderHandle(reader).GetTypeForwarder(reader);
                        ScopeReferenceHandle destinationScope = typeForwarder.Scope;
                        RuntimeAssemblyName destinationAssemblyName = destinationScope.ToRuntimeAssemblyName(reader);
                        RuntimeAssembly destinationAssembly;
                        Exception exception = RuntimeAssembly.TryGetRuntimeAssembly(reflectionDomain, destinationAssemblyName, out destinationAssembly);
                        if (exception != null)
                        {
                            result = null;
                            return exception;
                        }
                        return TryResolveCaseInsensitive(reflectionDomain, destinationAssembly, out result);
                    }
                default:
                    throw new InvalidOperationException();
            }
        }