public static string GetFullName(this ScopeDefinitionHandle scopeDefHandle, MetadataReader reader)
        {
            var scopeDef = scopeDefHandle.GetScopeDefinition(reader);

            Debug.Assert(!scopeDef.Name.IsNull(reader));

            var assemblyName = new AssemblyName
            {
                Name        = scopeDef.Name.GetConstantStringValue(reader).Value,
                CultureName = scopeDef.Culture.IsNull(reader) ? null : scopeDef.Culture.GetConstantStringValue(reader).Value,
                Version     = new Version(scopeDef.MajorVersion, scopeDef.MinorVersion, scopeDef.BuildNumber, scopeDef.RevisionNumber)
            };

            if (scopeDef.PublicKey.Count > 0)
            {
                var pkt   = new byte[scopeDef.PublicKey.Count];
                int index = 0;
                foreach (var b in scopeDef.PublicKey)
                {
                    pkt[index++] = b;
                }
                assemblyName.SetPublicKeyToken(pkt);
            }
            else
            {
                assemblyName.SetPublicKeyToken(Array.Empty <byte>());
            }

            return(assemblyName.FullName);
        }
예제 #2
0
        public NativeFormatModule GetModuleFromAssemblyName(string assemblyNameString)
        {
            AssemblyBindResult  bindResult;
            RuntimeAssemblyName assemblyName = AssemblyNameParser.Parse(assemblyNameString);
            Exception           failureException;

            if (!AssemblyBinderImplementation.Instance.Bind(assemblyName, cacheMissedLookups: true, out bindResult, out failureException))
            {
                throw failureException;
            }

            var moduleList = Internal.Runtime.TypeLoader.ModuleList.Instance;
            NativeFormatModuleInfo primaryModule = moduleList.GetModuleInfoForMetadataReader(bindResult.Reader);

            // If this isn't the primary module, defer to that module to load the MetadataUnit
            if (primaryModule != _module)
            {
                return(Context.ResolveMetadataUnit(primaryModule).GetModule(bindResult.ScopeDefinitionHandle));
            }

            // Setup arguments and allocate the NativeFormatModule
            ArrayBuilder <NativeFormatModule.QualifiedScopeDefinition> qualifiedScopes = new ArrayBuilder <NativeFormatModule.QualifiedScopeDefinition>();

            qualifiedScopes.Add(new NativeFormatModule.QualifiedScopeDefinition(this, bindResult.ScopeDefinitionHandle));

            foreach (QScopeDefinition scope in bindResult.OverflowScopes)
            {
                NativeFormatModuleInfo   module       = moduleList.GetModuleInfoForMetadataReader(scope.Reader);
                ScopeDefinitionHandle    scopeHandle  = scope.Handle;
                NativeFormatMetadataUnit metadataUnit = Context.ResolveMetadataUnit(module);
                qualifiedScopes.Add(new NativeFormatModule.QualifiedScopeDefinition(metadataUnit, scopeHandle));
            }

            return(new NativeFormatModule(Context, qualifiedScopes.ToArray()));
        }
예제 #3
0
        } // Read

        public static uint Read(this NativeReader reader, uint offset, out ScopeDefinitionHandle handle)
        {
            uint value;

            offset = reader.DecodeUnsigned(offset, out value);
            handle = new ScopeDefinitionHandle((int)value);
            handle._Validate();
            return(offset);
        } // Read
        internal sealed override RuntimeTypeInfo UncachedGetTypeCoreCaseSensitive(string fullName)
        {
            string[] parts             = fullName.Split('.');
            int      numNamespaceParts = parts.Length - 1;

            string[] namespaceParts = new string[numNamespaceParts];
            for (int i = 0; i < numNamespaceParts; i++)
            {
                namespaceParts[numNamespaceParts - i - 1] = parts[i];
            }
            string name = parts[numNamespaceParts];

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

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

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

                // No match found in this assembly - see if there's a matching type forwarder.
                TypeForwarderHandleCollection 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);
                        RuntimeAssemblyInfo redirectedAssembly     = RuntimeAssemblyInfo.GetRuntimeAssemblyIfExists(redirectedAssemblyName);
                        if (redirectedAssembly == null)
                        {
                            return(null);
                        }
                        return(redirectedAssembly.GetTypeCoreCaseSensitive(fullName));
                    }
                }
            }

            return(null);
        }
예제 #5
0
        public static RuntimeAssemblyName ToRuntimeAssemblyName(this ScopeDefinitionHandle scopeDefinitionHandle, MetadataReader reader)
        {
            ScopeDefinition scopeDefinition = scopeDefinitionHandle.GetScopeDefinition(reader);

            return(CreateRuntimeAssemblyNameFromMetadata(
                       reader,
                       scopeDefinition.Name,
                       scopeDefinition.MajorVersion,
                       scopeDefinition.MinorVersion,
                       scopeDefinition.BuildNumber,
                       scopeDefinition.RevisionNumber,
                       scopeDefinition.Culture,
                       scopeDefinition.PublicKey,
                       scopeDefinition.Flags
                       ));
        }
예제 #6
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));
            }
        }
        public sealed override bool Bind(AssemblyName refName, out MetadataReader reader, out ScopeDefinitionHandle scopeDefinitionHandle, out IEnumerable<QScopeDefinition> overflowScopes, out Exception exception)
        {
            bool foundMatch = false;
            reader = null;
            scopeDefinitionHandle = default(ScopeDefinitionHandle);
            exception = null;
            overflowScopes = null;

            foreach (KeyValuePair<string, ScopeDefinitionGroup> group in ScopeGroups)
            {
                AssemblyName defName = new AssemblyName(group.Key);
                if (AssemblyNameMatches(refName, defName))
                {
                    if (foundMatch)
                    {
                        exception = new AmbiguousMatchException();
                        return false;
                    }

                    foundMatch = true;
                    ScopeDefinitionGroup scopeDefinitionGroup = group.Value;

                    reader = scopeDefinitionGroup.CanonicalScope.Reader;
                    scopeDefinitionHandle = scopeDefinitionGroup.CanonicalScope.Handle;
                    overflowScopes = scopeDefinitionGroup.OverflowScopes;
                }
            }

            if (!foundMatch)
            {
                exception = new IOException(SR.Format(SR.FileNotFound_AssemblyNotFound, refName.FullName));
                return false;
            }

            return true;
        }
예제 #8
0
 internal new AssemblyName CreateAssemblyNameFromMetadata(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle)
 {
     return(base.CreateAssemblyNameFromMetadata(reader, scopeDefinitionHandle));
 }
예제 #9
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)));
 }
예제 #10
0
 private RuntimeAssembly(MetadataReader reader, ScopeDefinitionHandle scope, IEnumerable <QScopeDefinition> overflowScopes)
 {
     Scope          = new QScopeDefinition(reader, scope);
     OverflowScopes = overflowScopes;
 }
예제 #11
0
 // This helper is a concession to the fact that third-party binders running on top of the Win8P surface area have no sensible way
 // to perform this task due to the lack of a SetCulture() api on the AssemblyName class. Reflection.Core *is* able to do this 
 // thanks to the Internal.Reflection.Augment contract so we will expose this helper for the convenience of binders. 
 protected AssemblyName CreateAssemblyNameFromMetadata(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle)
 {
     return scopeDefinitionHandle.ToRuntimeAssemblyName(reader).ToAssemblyName();
 }
 //==============================================================================================
 // Pseudo Custom Attributes
 //==============================================================================================
 public sealed override IEnumerable<CustomAttributeData> GetPsuedoCustomAttributes(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle)
 {
     return Empty<CustomAttributeData>.Enumerable;
 }
예제 #13
0
 public NativeFormatModule GetModule(ScopeDefinitionHandle scopeHandle)
 {
     return((NativeFormatModule)GetObject(scopeHandle, null));
 }
예제 #14
0
        public static bool CompareScopeReferenceToDefinition(ScopeReferenceHandle sr1, MetadataReader mr1, ScopeDefinitionHandle sd2, MetadataReader mr2)
        {
            ScopeReference srData1 = mr1.GetScopeReference(sr1);
            ScopeDefinition sdData2 = mr2.GetScopeDefinition(sd2);
            if (!srData1.Name.StringEquals(sdData2.Name.GetConstantStringValue(mr2).Value, mr1))
                return false;

            if (!srData1.Culture.StringEquals(sdData2.Culture.GetConstantStringValue(mr2).Value, mr1))
                return false;

            if (srData1.MajorVersion != sdData2.MajorVersion)
                return false;

            if (srData1.MinorVersion != sdData2.MinorVersion)
                return false;

            if (srData1.RevisionNumber != sdData2.RevisionNumber)
                return false;

            if (srData1.BuildNumber != sdData2.BuildNumber)
                return false;

            return ComparePublicKeyOrTokens(srData1.PublicKeyOrToken, srData1.Flags.HasFlag(AssemblyFlags.PublicKey), sdData2.PublicKey, sdData2.Flags.HasFlag(AssemblyFlags.PublicKey));
        }
예제 #15
0
 internal static RuntimeAssembly GetRuntimeAssembly(MetadataReader reader, ScopeDefinitionHandle scope, IEnumerable <QScopeDefinition> overflowScopes)
 {
     return(s_scopeToAssemblyDispenser.GetOrAdd(new RuntimeAssemblyKey(reader, scope, overflowScopes)));
 }
        public static bool CompareScopeReferenceToDefinition(ScopeReferenceHandle sr1, MetadataReader mr1, ScopeDefinitionHandle sd2, MetadataReader mr2)
        {
            ScopeReference  srData1 = mr1.GetScopeReference(sr1);
            ScopeDefinition sdData2 = mr2.GetScopeDefinition(sd2);

            if (!srData1.Name.StringEquals(sdData2.Name.GetConstantStringValue(mr2).Value, mr1))
            {
                return(false);
            }

            if (!srData1.Culture.StringEquals(sdData2.Culture.GetConstantStringValue(mr2).Value, mr1))
            {
                return(false);
            }

            if (srData1.MajorVersion != sdData2.MajorVersion)
            {
                return(false);
            }

            if (srData1.MinorVersion != sdData2.MinorVersion)
            {
                return(false);
            }

            if (srData1.RevisionNumber != sdData2.RevisionNumber)
            {
                return(false);
            }

            if (srData1.BuildNumber != sdData2.BuildNumber)
            {
                return(false);
            }

            return(ComparePublicKeyOrTokens(srData1.PublicKeyOrToken, srData1.Flags.HasFlag(AssemblyFlags.PublicKey), sdData2.PublicKey, sdData2.Flags.HasFlag(AssemblyFlags.PublicKey)));
        }
예제 #17
0
 public abstract bool Bind(AssemblyName refName, out MetadataReader reader, out ScopeDefinitionHandle scopeDefinitionHandle, out IEnumerable <QScopeDefinition> overflowScopes, out Exception exception);
예제 #18
0
파일: TypeName.cs 프로젝트: noahfalk/corert
        private bool TryResolveNamespaceDefinitionCaseSensitive(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle, out NamespaceDefinition namespaceDefinition)
        {
            namespaceDefinition = scopeDefinitionHandle.GetScopeDefinition(reader).RootNamespaceDefinition.GetNamespaceDefinition(reader);
            IEnumerable<NamespaceDefinitionHandle> candidates = namespaceDefinition.NamespaceDefinitions;
            int idx = _namespaceParts.Length;
            while (idx-- != 0)
            {
                // Each iteration finds a match for one segment of the namespace chain.
                String expected = _namespaceParts[idx];
                bool foundMatch = false;
                foreach (NamespaceDefinitionHandle candidate in candidates)
                {
                    namespaceDefinition = candidate.GetNamespaceDefinition(reader);
                    if (namespaceDefinition.Name.StringOrNullEquals(expected, reader))
                    {
                        // Found a match for this segment of the namespace chain. Move on to the next level.
                        foundMatch = true;
                        candidates = namespaceDefinition.NamespaceDefinitions;
                        break;
                    }
                }

                if (!foundMatch)
                {
                    return false;
                }
            }

            return true;
        }
예제 #19
0
 // This helper is a concession to the fact that third-party binders running on top of the Win8P surface area have no sensible way
 // to perform this task due to the lack of a SetCulture() api on the AssemblyName class. Reflection.Core *is* able to do this
 // thanks to the Internal.Reflection.Augment contract so we will expose this helper for the convenience of binders.
 protected AssemblyName CreateAssemblyNameFromMetadata(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle)
 {
     return(scopeDefinitionHandle.ToRuntimeAssemblyName(reader).ToAssemblyName());
 }
예제 #20
0
        public sealed override bool Bind(AssemblyName refName, out MetadataReader reader, out ScopeDefinitionHandle scopeDefinitionHandle, out IEnumerable <QScopeDefinition> overflowScopes, out Exception exception)
        {
            bool foundMatch = false;

            reader = null;
            scopeDefinitionHandle = default(ScopeDefinitionHandle);
            exception             = null;
            overflowScopes        = null;

            // At least one real-world app calls Type.GetType() for "char" using the assembly name "mscorlib". To accomodate this,
            // we will adopt the desktop CLR rule that anything named "mscorlib" automatically binds to the core assembly.
            bool         useMscorlibNameCompareFunc = false;
            AssemblyName compareRefName             = refName;

            if (refName.Name == "mscorlib")
            {
                useMscorlibNameCompareFunc = true;
                compareRefName             = new AssemblyName(AssemblyBinder.DefaultAssemblyNameForGetType);
            }

            foreach (KeyValuePair <AssemblyNameKey, ScopeDefinitionGroup> group in ScopeGroups)
            {
                bool nameMatches;
                if (useMscorlibNameCompareFunc)
                {
                    nameMatches = MscorlibAssemblyNameMatches(compareRefName, group.Key.AssemblyName);
                }
                else
                {
                    nameMatches = AssemblyNameMatches(refName, group.Key.AssemblyName);
                }

                if (nameMatches)
                {
                    if (foundMatch)
                    {
                        exception = new AmbiguousMatchException();
                        return(false);
                    }

                    foundMatch = true;
                    ScopeDefinitionGroup scopeDefinitionGroup = group.Value;

                    reader = scopeDefinitionGroup.CanonicalScope.Reader;
                    scopeDefinitionHandle = scopeDefinitionGroup.CanonicalScope.Handle;
                    overflowScopes        = scopeDefinitionGroup.OverflowScopes;
                }
            }

            if (!foundMatch)
            {
                exception = new IOException(SR.Format(SR.FileNotFound_AssemblyNotFound, refName.FullName));
                return(false);
            }

            return(true);
        }
예제 #21
0
        public sealed override bool Bind(AssemblyName refName, out MetadataReader reader, out ScopeDefinitionHandle scopeDefinitionHandle, out IEnumerable <QScopeDefinition> overflowScopes, out Exception exception)
        {
            bool foundMatch = false;

            reader = null;
            scopeDefinitionHandle = default(ScopeDefinitionHandle);
            exception             = null;
            overflowScopes        = null;

            foreach (KeyValuePair <string, ScopeDefinitionGroup> group in ScopeGroups)
            {
                AssemblyName defName = new AssemblyName(group.Key);
                if (AssemblyNameMatches(refName, defName))
                {
                    if (foundMatch)
                    {
                        exception = new AmbiguousMatchException();
                        return(false);
                    }

                    foundMatch = true;
                    ScopeDefinitionGroup scopeDefinitionGroup = group.Value;

                    reader = scopeDefinitionGroup.CanonicalScope.Reader;
                    scopeDefinitionHandle = scopeDefinitionGroup.CanonicalScope.Handle;
                    overflowScopes        = scopeDefinitionGroup.OverflowScopes;
                }
            }

            if (!foundMatch)
            {
                exception = new IOException(SR.Format(SR.FileNotFound_AssemblyNotFound, refName.FullName));
                return(false);
            }

            return(true);
        }
예제 #22
0
 //==============================================================================================
 // Pseudo Custom Attributes
 //==============================================================================================
 public abstract IEnumerable <CustomAttributeData> GetPsuedoCustomAttributes(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle);
 internal new AssemblyName CreateAssemblyNameFromMetadata(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle)
 {
     return base.CreateAssemblyNameFromMetadata(reader, scopeDefinitionHandle);
 }
예제 #24
0
파일: QHandles.cs 프로젝트: z77ma/runtime
 public QScopeDefinition(MetadataReader reader, ScopeDefinitionHandle handle)
 {
     _reader = reader;
     _handle = handle;
 }
예제 #25
0
 public abstract bool Bind(AssemblyName refName, out MetadataReader reader, out ScopeDefinitionHandle scopeDefinitionHandle, out IEnumerable<QScopeDefinition> overflowScopes, out Exception exception);
        private bool TryResolveNamespaceDefinitionCaseSensitive(MetadataReader reader, string[] namespaceParts, ScopeDefinitionHandle scopeDefinitionHandle, out NamespaceDefinition namespaceDefinition)
        {
            namespaceDefinition = scopeDefinitionHandle.GetScopeDefinition(reader).RootNamespaceDefinition.GetNamespaceDefinition(reader);
            NamespaceDefinitionHandleCollection candidates = namespaceDefinition.NamespaceDefinitions;
            int idx = namespaceParts.Length;

            while (idx-- != 0)
            {
                // Each iteration finds a match for one segment of the namespace chain.
                string expected   = namespaceParts[idx];
                bool   foundMatch = false;
                foreach (NamespaceDefinitionHandle candidate in candidates)
                {
                    namespaceDefinition = candidate.GetNamespaceDefinition(reader);
                    if (namespaceDefinition.Name.StringOrNullEquals(expected, reader))
                    {
                        // Found a match for this segment of the namespace chain. Move on to the next level.
                        foundMatch = true;
                        candidates = namespaceDefinition.NamespaceDefinitions;
                        break;
                    }
                }

                if (!foundMatch)
                {
                    return(false);
                }
            }

            return(true);
        }
 //==============================================================================================
 // Pseudo Custom Attributes
 //==============================================================================================
 public sealed override IEnumerable <CustomAttributeData> GetPsuedoCustomAttributes(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle)
 {
     return(Empty <CustomAttributeData> .Enumerable);
 }
예제 #28
0
 public RuntimeAssemblyKey(MetadataReader reader, ScopeDefinitionHandle handle, IEnumerable <QScopeDefinition> overflows)
 {
     _reader    = reader;
     _handle    = handle;
     _overflows = overflows;
 }
예제 #29
0
 //==============================================================================================
 // Pseudo Custom Attributes
 //==============================================================================================
 public abstract IEnumerable<CustomAttributeData> GetPsuedoCustomAttributes(MetadataReader reader, ScopeDefinitionHandle scopeDefinitionHandle);