Example #1
0
        public static bool CompareTypeReferenceToDefinition(TypeReferenceHandle tr1, MetadataReader mr1, TypeDefinitionHandle td2, MetadataReader mr2)
        {
            // TODO! The correct implementation here is probably to call into the assembly binder, but that's not available due to layering.
            // For now, just implement comparison, which will be equivalent in all cases until we support loading multiple copies of the same assembly

            TypeReference trData1 = mr1.GetTypeReference(tr1);
            TypeDefinition tdData2 = mr2.GetTypeDefinition(td2);

            if (!trData1.TypeName.StringEquals(tdData2.Name.GetConstantStringValue(mr2).Value, mr1))
                return false;

            switch (trData1.ParentNamespaceOrType.HandleType)
            {
                case HandleType.TypeReference:
                    if (tdData2.EnclosingType.IsNull(mr2))
                        return false;

                    return CompareTypeReferenceToDefinition(trData1.ParentNamespaceOrType.ToTypeReferenceHandle(mr1), mr1, tdData2.EnclosingType, mr2);

                case HandleType.NamespaceReference:
                    return CompareNamespaceReferenceToDefinition(trData1.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr1), mr1, tdData2.NamespaceDefinition, mr2);

                default:
                    Debug.Assert(false);
                    throw new BadImageFormatException();
            }
        }
Example #2
0
        private int GetProjectionIndexForTypeReference(TypeReferenceHandle typeRef, out bool isIDisposable)
        {
            InitializeProjectedTypes();

            int index = StringStream.BinarySearchRaw(s_projectedTypeNames, TypeRefTable.GetName(typeRef));
            if (index >= 0 && StringStream.EqualsRaw(TypeRefTable.GetNamespace(typeRef), s_projectionInfos[index].WinRTNamespace))
            {
                isIDisposable = s_projectionInfos[index].IsIDisposable;
                return index;
            }

            isIDisposable = false;
            return -1;
        }
Example #3
0
        public static bool CompareTypeReferenceAcrossModules(TypeReferenceHandle tr1, MetadataReader mr1, TypeReferenceHandle tr2, MetadataReader mr2)
        {
            TypeReference trData1 = mr1.GetTypeReference(tr1);
            TypeReference trData2 = mr2.GetTypeReference(tr2);
            if (!trData1.TypeName.StringEquals(trData2.TypeName.GetConstantStringValue(mr2).Value, mr1))
                return false;

            if (trData1.ParentNamespaceOrType.HandleType != trData2.ParentNamespaceOrType.HandleType)
                return false;

            if (trData1.ParentNamespaceOrType.HandleType == HandleType.TypeReference)
                return CompareTypeReferenceAcrossModules(trData1.ParentNamespaceOrType.ToTypeReferenceHandle(mr1), mr1, trData2.ParentNamespaceOrType.ToTypeReferenceHandle(mr2), mr2);

            return CompareNamespaceReferenceAcrossModules(trData1.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr1), mr1, trData2.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr2), mr2);
        }
        private static String GetTypeFullNameFromTypeRef(TypeReferenceHandle typeReferenceHandle, MetadataReader reader, List<int> genericParameterOffsets)
        {
            String s = "";

            TypeReference typeReference = typeReferenceHandle.GetTypeReference(reader);
            s = typeReference.TypeName.GetString(reader);
            Handle parentHandle = typeReference.ParentNamespaceOrType;
            HandleType parentHandleType = parentHandle.HandleType;
            if (parentHandleType == HandleType.TypeReference)
            {
                String containingTypeName = GetTypeFullNameFromTypeRef(parentHandle.ToTypeReferenceHandle(reader), reader, genericParameterOffsets);
                s = containingTypeName + "." + s;
            }
            else if (parentHandleType == HandleType.NamespaceReference)
            {
                NamespaceReferenceHandle namespaceReferenceHandle = parentHandle.ToNamespaceReferenceHandle(reader);
                for (; ;)
                {
                    NamespaceReference namespaceReference = namespaceReferenceHandle.GetNamespaceReference(reader);
                    String namespacePart = namespaceReference.Name.GetStringOrNull(reader);
                    if (namespacePart == null)
                        break; // Reached the root namespace.
                    s = namespacePart + "." + s;
                    if (namespaceReference.ParentScopeOrNamespace.HandleType != HandleType.NamespaceReference)
                        break; // Should have reached the root namespace first but this helper is for ToString() - better to
                    // return partial information than crash.
                    namespaceReferenceHandle = namespaceReference.ParentScopeOrNamespace.ToNamespaceReferenceHandle(reader);
                }
            }
            else
            {
                // If we got here, the metadata is illegal but this helper is for ToString() - better to 
                // return something partial than throw.
            }
            return ConvertBackTickNameToNameWithReducerInputFormat(s, genericParameterOffsets);
        }
 public override string GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, SignatureTypeHandleCode code)
 {
     return GetTypeFromHandle(reader, handle);
 }
Example #6
0
 public virtual string GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind = 0)
 {
     return(MetadataNameFormatter.FormatHandle(reader, handle));
 }
 public Mapping<TypeReferenceHandle> MapTypeReference(TypeReferenceHandle handle)
 {
     return _typeReferences.GetOrAdd(handle, MapTypeReferenceImpl);
 }
Example #8
0
 internal EntityHandle GetResolutionScope(TypeReferenceHandle handle)
 {
     int rowOffset = (handle.RowId - 1) * this.RowSize;
     return ResolutionScopeTag.ConvertToHandle(this.Block.PeekTaggedReference(rowOffset + _ResolutionScopeOffset, _IsResolutionScopeRefSizeSmall));
 }
Example #9
0
 private string GetFullName(TypeReferenceHandle handle)
 {
     return(GetFullName(Reader.GetTypeReference(handle)));
 }
Example #10
0
 private bool IsSystemEnum(TypeReferenceHandle handle)
 {
     return(StringStream.EqualsRaw(TypeRefTable.GetNamespace(handle), "System") &&
            StringStream.EqualsRaw(TypeRefTable.GetName(handle), "Enum"));
 }
Example #11
0
 // cf. MetadataDecoder<>.GetTypeOfTypeRef.
 private TypeSignature DecodeTypeReference(
     TypeReferenceHandle handle,
     ImmutableArray<TypeSignature> typeArguments,
     ref int typeArgumentOffset)
 {
     var typeRef = _reader.GetTypeReference(handle);
     TypeSignature qualifier;
     var scope = typeRef.ResolutionScope;
     switch (scope.Kind)
     {
         case HandleKind.AssemblyReference:
         case HandleKind.ModuleReference:
             // Include namespace.
             qualifier = GetNamespace(typeRef.Namespace);
             break;
         case HandleKind.TypeReference:
             // Include declaring type.
             qualifier = DecodeTypeReference((TypeReferenceHandle)scope, typeArguments, ref typeArgumentOffset);
             break;
         default:
             throw new BadImageFormatException();
     }
     return CreateTypeSignature(qualifier, _reader.GetString(typeRef.Name), typeArguments, ref typeArgumentOffset);
 }
Example #12
0
        public TokenSearchResult GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
        {
            var t = currentModule.ResolveType(handle, default);

            return(GetResultFromResolvedType(t));
        }
 public string GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, SignatureTypeHandleCode code)
 {
     return(string.Empty);
 }
 public object GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
 {
     return(null !);
 }
 public PrimitiveTypeCode?GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) => null;
Example #16
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.
        }
Example #17
0
 private bool IsSystemAttribute(TypeReferenceHandle handle)
 {
     return(StringHeap.EqualsRaw(TypeRefTable.GetNamespace(handle), "System") &&
            StringHeap.EqualsRaw(TypeRefTable.GetName(handle), "Attribute"));
 }
Example #18
0
 public KnownType GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
 {
     return(KnownType.Unknown);
 }
Example #19
0
        public override void GetTypeRefProps(
            TypeReferenceHandle typeRef,
            out string name,
            out string @namespace,
            out MetadataToken resolutionScope)
        {
            base.GetTypeRefProps(typeRef, out name, out @namespace, out resolutionScope);

// TODO (tomat): disable the warning temporarily until we move this code to the metadata reader
#pragma warning disable 618 // obsolete warning reported when RowIds are used
            uint assemblyRefOffset;
            string clrName, clrNamespace;
            if (WinRTProjectedTypes.ResolveWinRTTypeReference(name, @namespace, out clrName, out clrNamespace, out assemblyRefOffset))
            {
                name = clrName;
                @namespace = clrNamespace;
                uint assemblyRefRid = this.winMdStartIndex + assemblyRefOffset + 1;
                resolutionScope = AssemblyReferenceHandle.FromRowId(assemblyRefRid);
            }
            else if (GetTypeRefTreatment(typeRef) != TypeRefTreatment.None)
            {
                uint assemblyRefRid = this.winMdStartIndex + (uint)WinMdAssembliesOffsets.SystemRuntime + 1;
                resolutionScope = AssemblyReferenceHandle.FromRowId(assemblyRefRid);
            }
#pragma warning restore 618 // obsolete warning reported when RowIds are used
        }
        public static bool CompareTypeReferenceAcrossModules(TypeReferenceHandle tr1, MetadataReader mr1, TypeReferenceHandle tr2, MetadataReader mr2)
        {
            TypeReference trData1 = mr1.GetTypeReference(tr1);
            TypeReference trData2 = mr2.GetTypeReference(tr2);

            if (!trData1.TypeName.StringEquals(trData2.TypeName.GetConstantStringValue(mr2).Value, mr1))
            {
                return(false);
            }

            if (trData1.ParentNamespaceOrType.HandleType != trData2.ParentNamespaceOrType.HandleType)
            {
                return(false);
            }

            if (trData1.ParentNamespaceOrType.HandleType == HandleType.TypeReference)
            {
                return(CompareTypeReferenceAcrossModules(trData1.ParentNamespaceOrType.ToTypeReferenceHandle(mr1), mr1, trData2.ParentNamespaceOrType.ToTypeReferenceHandle(mr2), mr2));
            }

            return(CompareNamespaceReferenceAcrossModules(trData1.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr1), mr1, trData2.ParentNamespaceOrType.ToNamespaceReferenceHandle(mr2), mr2));
        }
Example #21
0
 public string GetTypeFromReference(TypeReferenceHandle handle, bool? isValueType)
 {
     var typeRef = _reader.GetTypeReference(handle);
     var name = _reader.GetString(typeRef.Name);
     return typeRef.Namespace.IsNil ? name : _reader.GetString(typeRef.Namespace) + "." + name;
 }
Example #22
0
 internal Handle GetResolutionScope(TypeReferenceHandle handle)
 {
     int rowOffset = (int)(handle.RowId - 1) * this.RowSize;
     return ResolutionScopeTag.ConvertToToken(this.Block.PeekTaggedReference(rowOffset + this.ResolutionScopeOffset, this.IsResolutionScopeRefSizeSmall));
 }
 public override string GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
 {
     return FormatToken(handle);
 }
Example #24
0
 internal StringHandle GetNamespace(TypeReferenceHandle handle)
 {
     int rowOffset = (int)(handle.RowId - 1) * this.RowSize;
     return StringHandle.FromIndex(this.Block.PeekReference(rowOffset + this.NamespaceOffset, this.IsStringHeapRefSizeSmall));
 }
Example #25
0
 public abstract bool TryGetTypeReferenceForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeReferenceHandle typeRefHandle);
Example #26
0
 public abstract bool TryGetTypeReferenceForNamedType(RuntimeTypeHandle runtimeTypeHandle, out MetadataReader metadataReader, out TypeReferenceHandle typeRefHandle);
Example #27
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.
        }
Example #28
0
 public abstract bool TryGetNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle);
Example #29
0
        public void IsNil()
        {
            Assert.False(ModuleDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(AssemblyDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(InterfaceImplementationHandle.FromRowId(1).IsNil);
            Assert.False(MethodDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(MethodSpecificationHandle.FromRowId(1).IsNil);
            Assert.False(TypeDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(ExportedTypeHandle.FromRowId(1).IsNil);
            Assert.False(TypeReferenceHandle.FromRowId(1).IsNil);
            Assert.False(TypeSpecificationHandle.FromRowId(1).IsNil);
            Assert.False(MemberReferenceHandle.FromRowId(1).IsNil);
            Assert.False(FieldDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(EventDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(PropertyDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(StandaloneSignatureHandle.FromRowId(1).IsNil);
            Assert.False(MemberReferenceHandle.FromRowId(1).IsNil);
            Assert.False(FieldDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(EventDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(PropertyDefinitionHandle.FromRowId(1).IsNil);
            Assert.False(ParameterHandle.FromRowId(1).IsNil);
            Assert.False(GenericParameterHandle.FromRowId(1).IsNil);
            Assert.False(GenericParameterConstraintHandle.FromRowId(1).IsNil);
            Assert.False(ModuleReferenceHandle.FromRowId(1).IsNil);
            Assert.False(CustomAttributeHandle.FromRowId(1).IsNil);
            Assert.False(DeclarativeSecurityAttributeHandle.FromRowId(1).IsNil);
            Assert.False(ManifestResourceHandle.FromRowId(1).IsNil);
            Assert.False(ConstantHandle.FromRowId(1).IsNil);
            Assert.False(ManifestResourceHandle.FromRowId(1).IsNil);
            Assert.False(AssemblyFileHandle.FromRowId(1).IsNil);
            Assert.False(MethodImplementationHandle.FromRowId(1).IsNil);
            Assert.False(AssemblyReferenceHandle.FromRowId(1).IsNil);

            Assert.False(((EntityHandle)ModuleDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)AssemblyDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)InterfaceImplementationHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MethodDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MethodSpecificationHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)TypeDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ExportedTypeHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)TypeReferenceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)TypeSpecificationHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MemberReferenceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)FieldDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)EventDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)PropertyDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)StandaloneSignatureHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MemberReferenceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)FieldDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)EventDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)PropertyDefinitionHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ParameterHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)GenericParameterHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)GenericParameterConstraintHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ModuleReferenceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)CustomAttributeHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)DeclarativeSecurityAttributeHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ManifestResourceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ConstantHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)ManifestResourceHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)AssemblyFileHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)MethodImplementationHandle.FromRowId(1)).IsNil);
            Assert.False(((EntityHandle)AssemblyReferenceHandle.FromRowId(1)).IsNil);

            Assert.False(StringHandle.FromOffset(1).IsNil);
            Assert.False(BlobHandle.FromOffset(1).IsNil);
            Assert.False(UserStringHandle.FromOffset(1).IsNil);
            Assert.False(GuidHandle.FromIndex(1).IsNil);
            Assert.False(DocumentNameBlobHandle.FromOffset(1).IsNil);

            Assert.False(((Handle)StringHandle.FromOffset(1)).IsNil);
            Assert.False(((Handle)BlobHandle.FromOffset(1)).IsNil);
            Assert.False(((Handle)UserStringHandle.FromOffset(1)).IsNil);
            Assert.False(((Handle)GuidHandle.FromIndex(1)).IsNil);
            Assert.False(((BlobHandle)DocumentNameBlobHandle.FromOffset(1)).IsNil);

            Assert.True(ModuleDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(AssemblyDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(InterfaceImplementationHandle.FromRowId(0).IsNil);
            Assert.True(MethodDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(MethodSpecificationHandle.FromRowId(0).IsNil);
            Assert.True(TypeDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(ExportedTypeHandle.FromRowId(0).IsNil);
            Assert.True(TypeReferenceHandle.FromRowId(0).IsNil);
            Assert.True(TypeSpecificationHandle.FromRowId(0).IsNil);
            Assert.True(MemberReferenceHandle.FromRowId(0).IsNil);
            Assert.True(FieldDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(EventDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(PropertyDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(StandaloneSignatureHandle.FromRowId(0).IsNil);
            Assert.True(MemberReferenceHandle.FromRowId(0).IsNil);
            Assert.True(FieldDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(EventDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(PropertyDefinitionHandle.FromRowId(0).IsNil);
            Assert.True(ParameterHandle.FromRowId(0).IsNil);
            Assert.True(GenericParameterHandle.FromRowId(0).IsNil);
            Assert.True(GenericParameterConstraintHandle.FromRowId(0).IsNil);
            Assert.True(ModuleReferenceHandle.FromRowId(0).IsNil);
            Assert.True(CustomAttributeHandle.FromRowId(0).IsNil);
            Assert.True(DeclarativeSecurityAttributeHandle.FromRowId(0).IsNil);
            Assert.True(ManifestResourceHandle.FromRowId(0).IsNil);
            Assert.True(ConstantHandle.FromRowId(0).IsNil);
            Assert.True(ManifestResourceHandle.FromRowId(0).IsNil);
            Assert.True(AssemblyFileHandle.FromRowId(0).IsNil);
            Assert.True(MethodImplementationHandle.FromRowId(0).IsNil);
            Assert.True(AssemblyReferenceHandle.FromRowId(0).IsNil);

            Assert.True(((EntityHandle)ModuleDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)AssemblyDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)InterfaceImplementationHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MethodDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MethodSpecificationHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)TypeDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ExportedTypeHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)TypeReferenceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)TypeSpecificationHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MemberReferenceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)FieldDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)EventDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)PropertyDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)StandaloneSignatureHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MemberReferenceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)FieldDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)EventDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)PropertyDefinitionHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ParameterHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)GenericParameterHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)GenericParameterConstraintHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ModuleReferenceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)CustomAttributeHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)DeclarativeSecurityAttributeHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ManifestResourceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ConstantHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)ManifestResourceHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)AssemblyFileHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)MethodImplementationHandle.FromRowId(0)).IsNil);
            Assert.True(((EntityHandle)AssemblyReferenceHandle.FromRowId(0)).IsNil);

            // heaps:
            Assert.True(StringHandle.FromOffset(0).IsNil);
            Assert.True(BlobHandle.FromOffset(0).IsNil);
            Assert.True(UserStringHandle.FromOffset(0).IsNil);
            Assert.True(GuidHandle.FromIndex(0).IsNil);
            Assert.True(DocumentNameBlobHandle.FromOffset(0).IsNil);

            Assert.True(((Handle)StringHandle.FromOffset(0)).IsNil);
            Assert.True(((Handle)BlobHandle.FromOffset(0)).IsNil);
            Assert.True(((Handle)UserStringHandle.FromOffset(0)).IsNil);
            Assert.True(((Handle)GuidHandle.FromIndex(0)).IsNil);
            Assert.True(((BlobHandle)DocumentNameBlobHandle.FromOffset(0)).IsNil);

            // virtual:
            Assert.False(AssemblyReferenceHandle.FromVirtualIndex(0).IsNil);
            Assert.False(StringHandle.FromVirtualIndex(0).IsNil);
            Assert.False(BlobHandle.FromVirtualIndex(0, 0).IsNil);

            Assert.False(((Handle)AssemblyReferenceHandle.FromVirtualIndex(0)).IsNil);
            Assert.False(((Handle)StringHandle.FromVirtualIndex(0)).IsNil);
            Assert.False(((Handle)BlobHandle.FromVirtualIndex(0, 0)).IsNil);
        }
Example #30
0
 private TypeReferenceHandle Import(TypeReferenceHandle srcHandle) =>
 ImportEntity(srcHandle, _typeReferenceCache, _reader.GetTypeReference,
              src => _builder.AddTypeReference(Import(src.ResolutionScope), ImportValue(src.Namespace),
                                               ImportValue(src.Name)),
              _reader.ToString, IsNil);
Example #31
0
 public static TypeReference GetTypeReference(this TypeReferenceHandle handle, MetadataReader reader) => reader.GetTypeReference(handle);
Example #32
0
 public TypeDesc GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
 {
     Debug.Assert(reader == _module.MetadataReader);
     return(_module.GetType(handle));
 }
 private Mapping<TypeReferenceHandle> MapTypeReferenceImpl(TypeReferenceHandle handle)
 {
     throw new NotImplementedException();
 }
Example #34
0
 private static bool IsNil(TypeReferenceHandle x) => x.IsNil;
Example #35
0
 public object GetTypeFromReference(TypeReferenceHandle handle, bool? isValueType) => null;
 public string GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
 {
     return(string.Empty);
 }
Example #37
0
        private TypeRefTreatment GetTypeRefTreatment(TypeReferenceHandle typeRef)
        {
            TypeReference reference = peFileReader.GetTypeReference(typeRef);
            if (peFileReader.StringStream.CheckForText(reference.Namespace, "System"))
            {
                if (peFileReader.StringStream.CheckForText(reference.Name, "MulticastDelegate"))
                {
                    return TypeRefTreatment.SystemDelegate;
                }
                
                if (peFileReader.StringStream.CheckForText(reference.Name, "Attribute"))
                {
                    return TypeRefTreatment.SystemAttribute;
                }
            }

            return TypeRefTreatment.None;
        }
Example #38
0
        TypeDesc ISimpleTypeProvider <TypeDesc> .GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
        {
            var ecmaModule = (EcmaModule)_tsc.GetModuleForSimpleName(reader.GetString(reader.GetAssemblyDefinition().Name));

            return((TypeDesc)ecmaModule.GetObject(handle, NotFoundBehavior.ReturnNull));
        }
Example #39
0
        public static Type GetTypeFromReference(MetadataReader reader, Module aModule, TypeReferenceHandle handle, byte rawTypeKind)
        {
            int xToken = MetadataTokens.GetToken(handle);

            return(aModule.ResolveType(xToken, null, null));
        }
Example #40
0
 IrisType ITypeProvider <IrisType> .GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, SignatureTypeHandleCode code)
 {
     // We shouldn't be referencing any non-primitive types.
     return(IrisType.Invalid);
 }
 private bool IsSystemAttribute(TypeReferenceHandle handle)
 {
     return StringHeap.EqualsRaw(TypeRefTable.GetNamespace(handle), "System") &&
            StringHeap.EqualsRaw(TypeRefTable.GetName(handle), "Attribute");
 }
Example #42
0
        public static string GetFullTypeName(this MetadataReader metadataReader, TypeReferenceHandle typeReferenceHandle)
        {
            var typeReference = metadataReader.GetTypeReference(typeReferenceHandle);

            return(GetFullTypeName(metadataReader, typeReference));
        }
Example #43
0
 public static string GetFullTypeName(this MetadataReader metadataReader, TypeReferenceHandle typeReferenceHandle)
 {
     var typeReference = metadataReader.GetTypeReference(typeReferenceHandle);
     return GetFullTypeName(metadataReader, typeReference);
 }
 public EntityHandle GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) => handle;
 private void AddTypeReferenceNameParts(TypeReferenceHandle handle, List<string> simpleNames)
 {
     var typeReference = _metadataReader.GetTypeReference(handle);
     AddNamespaceParts(typeReference.Namespace, simpleNames);
     simpleNames.Add(GetMetadataNameWithoutBackticks(_metadataReader, typeReference.Name));
 }
Example #46
0
        internal uint CalculateTypeRefTreatmentAndRowId(TypeReferenceHandle handle)
        {
            Debug.Assert(_metadataKind != MetadataKind.Ecma335);

            bool isIDisposable;
            int projectionIndex = GetProjectionIndexForTypeReference(handle, out isIDisposable);
            if (projectionIndex >= 0)
            {
                return TreatmentAndRowId((byte)TypeRefTreatment.UseProjectionInfo, projectionIndex);
            }
            else
            {
                return TreatmentAndRowId((byte)GetSpecialTypeRefTreatment(handle), handle.RowId);
            }
        }
Example #47
0
 public abstract bool TryGetNamedTypeForTypeReference(MetadataReader metadataReader, TypeReferenceHandle typeRefHandle, out RuntimeTypeHandle runtimeTypeHandle);
Example #48
0
 private bool IsSystemEnum(TypeReferenceHandle handle)
 {
     return StringStream.EqualsRaw(TypeRefTable.GetNamespace(handle), "System") &&
            StringStream.EqualsRaw(TypeRefTable.GetName(handle), "Enum");
 }
Example #49
0
 internal StringHandle GetNamespace(TypeReferenceHandle handle)
 {
     int rowOffset = (handle.RowId - 1) * this.RowSize;
     return StringHandle.FromOffset(this.Block.PeekHeapReference(rowOffset + _NamespaceOffset, _IsStringHeapRefSizeSmall));
 }
Example #50
0
 public TypeReference GetTypeReference(TypeReferenceHandle handle)
 {
     // PERF: This code pattern is JIT friendly and results in very efficient code.
     return new TypeReference(this, GetTypeRefTreatmentAndRowId(handle));
 }
Example #51
0
 public MType GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
 {
     return(ParseTypeReference(reader, handle));
 }
Example #52
0
 public object GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) => throw new NotImplementedException();
Example #53
0
        private TypeRefTreatment GetSpecialTypeRefTreatment(TypeReferenceHandle handle)
        {
            if (StringStream.EqualsRaw(TypeRefTable.GetNamespace(handle), "System"))
            {
                StringHandle name = TypeRefTable.GetName(handle);

                if (StringStream.EqualsRaw(name, "MulticastDelegate"))
                {
                    return TypeRefTreatment.SystemDelegate;
                }

                if (StringStream.EqualsRaw(name, "Attribute"))
                {
                    return TypeRefTreatment.SystemAttribute;
                }
            }

            return TypeRefTreatment.None;
        }
 public RoType GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) => handle.ResolveTypeRef(this);
Example #55
0
 public Type GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) =>
 (Type)cx.Create(handle);
Example #56
0
 public DummyTypeInfo GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind)
 {
     _resolver.AddModuleTokenForType((TypeDesc)_contextModule.GetObject(handle), new ModuleToken(_contextModule, handle));
     return(DummyTypeInfo.Instance);
 }
Example #57
0
        private uint GetTypeRefTreatmentAndRowId(TypeReferenceHandle handle)
        {
            // PERF: This code pattern is JIT friendly and results in very efficient code.
            if (this.metadataKind == MetadataKind.Ecma335)
            {
                return handle.RowId;
            }

            return CalculateTypeRefTreatmentAndRowId(handle);
        }
 public string GetTypeFromReference(MetadataReader reader, TypeReferenceHandle handle, byte rawTypeKind) => "";