Пример #1
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
                       ));
        }
Пример #2
0
        private void InitializeScopeDefinition(Cts.ModuleDesc module, ScopeDefinition scopeDefinition)
        {
            // Make sure we're expected to create a scope definition here. If the assert fires, the metadata
            // policy should have directed us to create a scope reference (or the list of inputs was incomplete).
            Debug.Assert(_modulesToTransform.Contains(module), "Incomplete list of input modules with respect to metadata policy");

            var assemblyDesc = module as Cts.IAssemblyDesc;

            if (assemblyDesc != null)
            {
                var assemblyName = assemblyDesc.GetName();

                scopeDefinition.Name           = HandleString(assemblyName.Name);
                scopeDefinition.Culture        = HandleString(assemblyName.CultureName);
                scopeDefinition.MajorVersion   = checked ((ushort)assemblyName.Version.Major);
                scopeDefinition.MinorVersion   = checked ((ushort)assemblyName.Version.Minor);
                scopeDefinition.BuildNumber    = checked ((ushort)assemblyName.Version.Build);
                scopeDefinition.RevisionNumber = checked ((ushort)assemblyName.Version.Revision);

                Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey);
                Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable);
                scopeDefinition.Flags = (AssemblyFlags)assemblyName.Flags;

                if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
                {
                    scopeDefinition.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9);
                }

                scopeDefinition.PublicKey = assemblyName.GetPublicKey();

                // TODO: CustomAttributes
            }
            else
            {
                throw new NotSupportedException("Multi-module assemblies");
            }

            scopeDefinition.RootNamespaceDefinition = new NamespaceDefinition
            {
                Name = null,
                ParentScopeOrNamespace = scopeDefinition,
            };
        }
Пример #3
0
        private void InitializeScopeDefinition(Cts.ModuleDesc module, ScopeDefinition scopeDefinition)
        {
            var assemblyDesc = module as Cts.IAssemblyDesc;

            if (assemblyDesc != null)
            {
                var assemblyName = assemblyDesc.GetName();

                scopeDefinition.Name           = HandleString(assemblyName.Name);
                scopeDefinition.Culture        = HandleString(assemblyName.CultureName);
                scopeDefinition.MajorVersion   = checked ((ushort)assemblyName.Version.Major);
                scopeDefinition.MinorVersion   = checked ((ushort)assemblyName.Version.Minor);
                scopeDefinition.BuildNumber    = checked ((ushort)assemblyName.Version.Build);
                scopeDefinition.RevisionNumber = checked ((ushort)assemblyName.Version.Revision);

                Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey);
                Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable);
                scopeDefinition.Flags = (AssemblyFlags)assemblyName.Flags;

                if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
                {
                    scopeDefinition.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9);
                }

                scopeDefinition.PublicKey = assemblyName.GetPublicKey();

                // TODO: CustomAttributes
            }
            else
            {
                throw new NotSupportedException("Multi-module assemblies");
            }

            scopeDefinition.RootNamespaceDefinition = new NamespaceDefinition
            {
                Name = null,
                ParentScopeOrNamespace = scopeDefinition,
            };
        }
        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)));
        }
Пример #5
0
            protected override IHandleObject CreateValueFromKey(NativeFormatObjectKey key)
            {
                Handle           handle    = key.Handle;
                NativeFormatType container = key.Container;

                object item;

                switch (handle.HandleType)
                {
                case HandleType.TypeDefinition:
                    item = new NativeFormatType(_metadataUnit, handle.ToTypeDefinitionHandle(_metadataReader));
                    break;

                case HandleType.Method:
                    item = new NativeFormatMethod(container, handle.ToMethodHandle(_metadataReader));
                    break;

                case HandleType.Field:
                    item = new NativeFormatField(container, handle.ToFieldHandle(_metadataReader));
                    break;

                case HandleType.TypeReference:
                    item = _metadataUnit.ResolveTypeReference(handle.ToTypeReferenceHandle(_metadataReader));
                    break;

                case HandleType.MemberReference:
                    item = _metadataUnit.ResolveMemberReference(handle.ToMemberReferenceHandle(_metadataReader));
                    break;

                case HandleType.QualifiedMethod:
                    item = _metadataUnit.ResolveQualifiedMethod(handle.ToQualifiedMethodHandle(_metadataReader));
                    break;

                case HandleType.QualifiedField:
                    item = _metadataUnit.ResolveQualifiedField(handle.ToQualifiedFieldHandle(_metadataReader));
                    break;

                case HandleType.ScopeReference:
                    item = _metadataUnit.ResolveAssemblyReference(handle.ToScopeReferenceHandle(_metadataReader));
                    break;

                case HandleType.ScopeDefinition:
                {
                    ScopeDefinition scope = handle.ToScopeDefinitionHandle(_metadataReader).GetScopeDefinition(_metadataReader);
                    item = _metadataUnit.GetModuleFromAssemblyName(scope.Name.GetConstantStringValue(_metadataReader).Value);
                }
                break;

                case HandleType.TypeSpecification:
                case HandleType.TypeInstantiationSignature:
                case HandleType.SZArraySignature:
                case HandleType.ArraySignature:
                case HandleType.PointerSignature:
                case HandleType.ByReferenceSignature:
                case HandleType.TypeVariableSignature:
                case HandleType.MethodTypeVariableSignature:
                {
                    NativeFormatSignatureParser parser = new NativeFormatSignatureParser(_metadataUnit, handle, _metadataReader);

                    item = parser.ParseTypeSignature();
                }
                break;

                case HandleType.MethodInstantiation:
                    item = _metadataUnit.ResolveMethodInstantiation(handle.ToMethodInstantiationHandle(_metadataReader));
                    break;

                // TODO: Resolve other tokens
                default:
                    throw new BadImageFormatException("Unknown metadata token type: " + handle.HandleType);
                }

                switch (handle.HandleType)
                {
                case HandleType.TypeDefinition:
                case HandleType.Field:
                case HandleType.Method:
                    // type/method/field definitions directly correspond to their target item.
                    return((IHandleObject)item);

                default:
                    // Everything else is some form of reference which cannot be self-describing
                    return(new NativeFormatObjectLookupWrapper(handle, item, container));
                }
            }
Пример #6
0
        private void InitializeScopeDefinition(Cts.ModuleDesc module, ScopeDefinition scopeDefinition)
        {
            var assemblyDesc = module as Cts.IAssemblyDesc;

            if (assemblyDesc != null)
            {
                var assemblyName = assemblyDesc.GetName();

                scopeDefinition.Name = HandleString(assemblyName.Name);
#if NETFX_45
                // With NET 4.5 contract System.Reflection 4.0.0.0 EcmaModule has no way
                // to set Culture in its AssemblyName.
                scopeDefinition.Culture = HandleString(assemblyName.CultureName ?? "");
#else
                scopeDefinition.Culture = HandleString(assemblyName.CultureName);
#endif
                scopeDefinition.MajorVersion   = checked ((ushort)assemblyName.Version.Major);
                scopeDefinition.MinorVersion   = checked ((ushort)assemblyName.Version.Minor);
                scopeDefinition.BuildNumber    = checked ((ushort)assemblyName.Version.Build);
                scopeDefinition.RevisionNumber = checked ((ushort)assemblyName.Version.Revision);

                Debug.Assert((int)AssemblyFlags.PublicKey == (int)AssemblyNameFlags.PublicKey);
                Debug.Assert((int)AssemblyFlags.Retargetable == (int)AssemblyNameFlags.Retargetable);
                scopeDefinition.Flags = (AssemblyFlags)assemblyName.Flags;

                if (assemblyName.ContentType == AssemblyContentType.WindowsRuntime)
                {
                    scopeDefinition.Flags |= (AssemblyFlags)((int)AssemblyContentType.WindowsRuntime << 9);
                }

                if ((scopeDefinition.Flags & AssemblyFlags.PublicKey) != 0)
                {
                    scopeDefinition.PublicKey = assemblyName.GetPublicKey();
                }
                else
                {
                    scopeDefinition.PublicKey = assemblyName.GetPublicKeyToken();
                }

                Cts.MetadataType moduleType = module.GetGlobalModuleType();
                if (moduleType != null && _policy.GeneratesMetadata(moduleType))
                {
                    scopeDefinition.GlobalModuleType = (TypeDefinition)HandleType(moduleType);
                }

                Cts.Ecma.EcmaAssembly ecmaAssembly = module as Cts.Ecma.EcmaAssembly;
                if (ecmaAssembly != null)
                {
                    Ecma.CustomAttributeHandleCollection customAttributes = ecmaAssembly.AssemblyDefinition.GetCustomAttributes();
                    if (customAttributes.Count > 0)
                    {
                        scopeDefinition.CustomAttributes = HandleCustomAttributes(ecmaAssembly, customAttributes);
                    }

                    Cts.MethodDesc entryPoint = ecmaAssembly.EntryPoint;
                    if (entryPoint != null && _policy.GeneratesMetadata(entryPoint))
                    {
                        scopeDefinition.EntryPoint = (QualifiedMethod)HandleQualifiedMethod(entryPoint);
                    }
                }
            }
            else
            {
                throw new NotSupportedException("Multi-module assemblies");
            }
        }
Пример #7
0
 public static IEnumerable <TypeDefinition> GetAllTypes(this ScopeDefinition scope)
 {
     return(scope.RootNamespaceDefinition.GetAllTypes());
 }