Example #1
0
        private string GetBaseTypeName(MetadataReader mdReader, TypeDefinition type)
        {
            EntityHandle baseTypeHandle = type.BaseType;

            if (baseTypeHandle.IsNil)
            {
                return(String.Empty);
            }

            HandleKind baseTypeHandleKind = baseTypeHandle.Kind;

            if (baseTypeHandleKind == HandleKind.TypeDefinition)
            {
                TypeDefinition baseType = mdReader.GetTypeDefinition((TypeDefinitionHandle)baseTypeHandle);
                return(mdReader.GetString(baseType.Namespace) + "." + mdReader.GetString(baseType.Name));
            }
            else if (baseTypeHandleKind == HandleKind.TypeSpecification)
            {
                TypeSpecification baseType = mdReader.GetTypeSpecification((TypeSpecificationHandle)baseTypeHandle);

                // Don't have logic to convert signatures to names/strings
                // NOTE: Enums and Structs can't have user defined base types, so this shouldn't break distinguising enums/structs.
                return(String.Empty);
            }
            else if (baseTypeHandleKind == HandleKind.TypeReference)
            {
                TypeReference baseType = mdReader.GetTypeReference((TypeReferenceHandle)baseTypeHandle);
                return(mdReader.GetString(baseType.Namespace) + "." + mdReader.GetString(baseType.Name));
            }

            return(String.Empty);
        }
Example #2
0
        public static BBoxHandle GetSelectionHandle(Rect bounds, HandleKind kind, float rescale)
        {
            Vector2 pos;
            var     radius = 4f * rescale;
            var     margin = 4.5f * rescale;

            if (kind.HasFlag(HandleKind.Right))
            {
                pos.X = bounds.Right + radius + margin;
            }
            else if (kind.HasFlag(HandleKind.Left))
            {
                pos.X = bounds.Left - radius - margin;
            }
            else
            {
                pos.X = .5f * (bounds.Left + bounds.Right);
            }

            if (kind.HasFlag(HandleKind.Top))
            {
                pos.Y = bounds.Top + radius + margin;
            }
            else if (kind.HasFlag(HandleKind.Bottom))
            {
                pos.Y = bounds.Bottom - radius - margin;
            }
            else
            {
                pos.Y = .5f * (bounds.Bottom + bounds.Top);
            }

            return(new BBoxHandle(kind, pos));
        }
Example #3
0
        private static HasCustomAttribute ToHasCustomAttributeTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.MethodDefinition: return HasCustomAttribute.MethodDef;
                case HandleKind.FieldDefinition: return HasCustomAttribute.Field;
                case HandleKind.TypeReference: return HasCustomAttribute.TypeRef;
                case HandleKind.TypeDefinition: return HasCustomAttribute.TypeDef;
                case HandleKind.Parameter: return HasCustomAttribute.Param;
                case HandleKind.InterfaceImplementation: return HasCustomAttribute.InterfaceImpl;
                case HandleKind.MemberReference: return HasCustomAttribute.MemberRef;
                case HandleKind.ModuleDefinition: return HasCustomAttribute.Module;
                case HandleKind.DeclarativeSecurityAttribute: return HasCustomAttribute.DeclSecurity;
                case HandleKind.PropertyDefinition: return HasCustomAttribute.Property;
                case HandleKind.EventDefinition: return HasCustomAttribute.Event;
                case HandleKind.StandaloneSignature: return HasCustomAttribute.StandAloneSig;
                case HandleKind.ModuleReference: return HasCustomAttribute.ModuleRef;
                case HandleKind.TypeSpecification: return HasCustomAttribute.TypeSpec;
                case HandleKind.AssemblyDefinition: return HasCustomAttribute.Assembly;
                case HandleKind.AssemblyReference: return HasCustomAttribute.AssemblyRef;
                case HandleKind.AssemblyFile: return HasCustomAttribute.File;
                case HandleKind.ExportedType: return HasCustomAttribute.ExportedType;
                case HandleKind.ManifestResource: return HasCustomAttribute.ManifestResource;
                case HandleKind.GenericParameter: return HasCustomAttribute.GenericParam;
                case HandleKind.GenericParameterConstraint: return HasCustomAttribute.GenericParamConstraint;
                case HandleKind.MethodSpecification: return HasCustomAttribute.MethodSpec;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="val"></param>
 internal InputArray(double val)
 {
     handle = Marshal.AllocHGlobal(sizeof(double));
     Marshal.StructureToPtr(val, handle, false);
     ptr        = NativeMethods.core_InputArray_new_byDouble(handle);
     handleKind = HandleKind.Double;
 }
        private static bool TryGetHandleRange(ImmutableArray <EntityHandle> handles, HandleKind handleKind, out int start, out int count)
        {
            TableIndex tableIndex;

            MetadataTokens.TryGetTableIndex(handleKind, out tableIndex);

            int mapIndex = ImmutableArray.BinarySearch <EntityHandle>(handles, MetadataTokens.EntityHandle(tableIndex, 0), TokenTypeComparer.Instance);

            if (mapIndex < 0)
            {
                start = 0;
                count = 0;
                return(false);
            }

            int s = mapIndex;

            while (s >= 0 && handles[s].Kind == handleKind)
            {
                s--;
            }

            int e = mapIndex;

            while (e < handles.Length && handles[e].Kind == handleKind)
            {
                e++;
            }

            start = s + 1;
            count = e - start;
            return(true);
        }
Example #6
0
        /// <summary>
        /// Gets the <see cref="HeapIndex"/> of the heap corresponding to the specified <see cref="HandleKind"/>.
        /// </summary>
        /// <param name="type">Handle type.</param>
        /// <param name="index">Heap index.</param>
        /// <returns>True if the handle type corresponds to an Ecma335 heap, false otherwise.</returns>
        public static bool TryGetHeapIndex(HandleKind type, out HeapIndex index)
        {
            switch (type)
            {
            case HandleKind.UserString:
                index = HeapIndex.UserString;
                return(true);

            case HandleKind.String:
            case HandleKind.NamespaceDefinition:
                index = HeapIndex.String;
                return(true);

            case HandleKind.Blob:
                index = HeapIndex.Blob;
                return(true);

            case HandleKind.Guid:
                index = HeapIndex.Guid;
                return(true);

            default:
                index = 0;
                return(false);
            }
        }
Example #7
0
        private static HasFieldMarshal ToHasFieldMarshalTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.FieldDefinition: return HasFieldMarshal.Field;
                case HandleKind.Parameter: return HasFieldMarshal.Param;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #8
0
        private static MemberForwarded ToMemberForwardedTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.FieldDefinition: return MemberForwarded.Field;
                case HandleKind.MethodDefinition: return MemberForwarded.MethodDef;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #9
0
        private static MethodDefOrRef ToMethodDefOrRefTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.MethodDefinition: return MethodDefOrRef.MethodDef;
                case HandleKind.MemberReference: return MethodDefOrRef.MemberRef;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #10
0
        private static TypeOrMethodDef ToTypeOrMethodDefTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.TypeDefinition: return TypeOrMethodDef.TypeDef;
                case HandleKind.MethodDefinition: return TypeOrMethodDef.MethodDef;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #11
0
        /// <summary>
        /// Gets the <see cref="TableIndex"/> of the table corresponding to the specified <see cref="HandleKind"/>.
        /// </summary>
        /// <param name="type">Handle type.</param>
        /// <param name="index">Table index.</param>
        /// <returns>True if the handle type corresponds to an Ecma335 table, false otherwise.</returns>
        public static bool TryGetTableIndex(HandleKind type, out TableIndex index)
        {
            if ((int)type < TableIndexExtensions.Count)
            {
                index = (TableIndex)type;
                return(true);
            }

            index = 0;
            return(false);
        }
Example #12
0
        private static CustomAttributeType ToCustomAttributeTypeTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.MethodDefinition: return CustomAttributeType.MethodDef;
                case HandleKind.MemberReference: return CustomAttributeType.MemberRef;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #13
0
        private static HasSemantics ToHasSemanticsTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.EventDefinition: return HasSemantics.Event;
                case HandleKind.PropertyDefinition: return HasSemantics.Property;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #14
0
        private static MethodDefOrRef ToMethodDefOrRefTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.MethodDefinition: return(MethodDefOrRef.MethodDef);

            case HandleKind.MemberReference: return(MethodDefOrRef.MemberRef);

            default:
                throw UnexpectedHandleKind(kind);
            }
        }
Example #15
0
        private static TypeDefOrRefOrSpec ToTypeDefOrRefTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.TypeDefinition: return(TypeDefOrRefOrSpec.TypeDef);

            case HandleKind.TypeReference: return(TypeDefOrRefOrSpec.TypeRef);

            default:
                throw UnexpectedHandleKind(kind);
            }
        }
Example #16
0
        private static MemberForwarded ToMemberForwardedTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.FieldDefinition: return(MemberForwarded.Field);

            case HandleKind.MethodDefinition: return(MemberForwarded.MethodDef);

            default:
                throw UnexpectedHandleKind(kind);
            }
        }
Example #17
0
        private static HasSemantics ToHasSemanticsTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.EventDefinition: return(HasSemantics.Event);

            case HandleKind.PropertyDefinition: return(HasSemantics.Property);

            default:
                throw UnexpectedHandleKind(kind);
            }
        }
Example #18
0
        private static HasFieldMarshal ToHasFieldMarshalTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.FieldDefinition: return(HasFieldMarshal.Field);

            case HandleKind.Parameter: return(HasFieldMarshal.Param);

            default:
                throw UnexpectedHandleKind(kind);
            }
        }
Example #19
0
        private static CustomAttributeType ToCustomAttributeTypeTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.MethodDefinition: return(CustomAttributeType.MethodDef);

            case HandleKind.MemberReference: return(CustomAttributeType.MemberRef);

            default:
                throw UnexpectedHandleKind(kind);
            }
        }
Example #20
0
        private static TypeOrMethodDef ToTypeOrMethodDefTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.TypeDefinition: return(TypeOrMethodDef.TypeDef);

            case HandleKind.MethodDefinition: return(TypeOrMethodDef.MethodDef);

            default:
                throw UnexpectedHandleKind(kind);
            }
        }
Example #21
0
        private static HasDeclSecurity ToHasDeclSecurityTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.TypeDefinition: return HasDeclSecurity.TypeDef;
                case HandleKind.MethodDefinition: return HasDeclSecurity.MethodDef;
                case HandleKind.AssemblyDefinition: return HasDeclSecurity.Assembly;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #22
0
        private static HasConstant ToHasConstantTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.FieldDefinition: return HasConstant.Field;
                case HandleKind.Parameter: return HasConstant.Param;
                case HandleKind.PropertyDefinition: return HasConstant.Property;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #23
0
        private static Implementation ToImplementationTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.AssemblyFile: return Implementation.File;
                case HandleKind.AssemblyReference: return Implementation.AssemblyRef;
                case HandleKind.ExportedType: return Implementation.ExportedType;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #24
0
        private static HasCustomAttributeTag ToHasCustomAttributeTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.MethodDefinition: return(HasCustomAttributeTag.MethodDef);

            case HandleKind.FieldDefinition: return(HasCustomAttributeTag.Field);

            case HandleKind.TypeReference: return(HasCustomAttributeTag.TypeRef);

            case HandleKind.TypeDefinition: return(HasCustomAttributeTag.TypeDef);

            case HandleKind.Parameter: return(HasCustomAttributeTag.Param);

            case HandleKind.InterfaceImplementation: return(HasCustomAttributeTag.InterfaceImpl);

            case HandleKind.MemberReference: return(HasCustomAttributeTag.MemberRef);

            case HandleKind.ModuleDefinition: return(HasCustomAttributeTag.Module);

            case HandleKind.DeclarativeSecurityAttribute: return(HasCustomAttributeTag.DeclSecurity);

            case HandleKind.PropertyDefinition: return(HasCustomAttributeTag.Property);

            case HandleKind.EventDefinition: return(HasCustomAttributeTag.Event);

            case HandleKind.StandaloneSignature: return(HasCustomAttributeTag.StandAloneSig);

            case HandleKind.ModuleReference: return(HasCustomAttributeTag.ModuleRef);

            case HandleKind.TypeSpecification: return(HasCustomAttributeTag.TypeSpec);

            case HandleKind.AssemblyDefinition: return(HasCustomAttributeTag.Assembly);

            case HandleKind.AssemblyReference: return(HasCustomAttributeTag.AssemblyRef);

            case HandleKind.AssemblyFile: return(HasCustomAttributeTag.File);

            case HandleKind.ExportedType: return(HasCustomAttributeTag.ExportedType);

            case HandleKind.ManifestResource: return(HasCustomAttributeTag.ManifestResource);

            case HandleKind.GenericParameter: return(HasCustomAttributeTag.GenericParam);

            case HandleKind.GenericParameterConstraint: return(HasCustomAttributeTag.GenericParamConstraint);

            case HandleKind.MethodSpecification: return(HasCustomAttributeTag.MethodSpec);

            default:
                Throw.InvalidArgument_UnexpectedHandleKind(kind);
                return(0);
            }
        }
Example #25
0
        private static TypeDefOrRefOrSpec ToTypeDefOrRefOrSpecTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.TypeDefinition: return TypeDefOrRefOrSpec.TypeDef;
                case HandleKind.TypeReference: return TypeDefOrRefOrSpec.TypeRef;
                case HandleKind.TypeSpecification: return TypeDefOrRefOrSpec.TypeSpec;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #26
0
        private static TypeOrMethodDefTag ToTypeOrMethodDefTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.TypeDefinition: return(TypeOrMethodDefTag.TypeDef);

            case HandleKind.MethodDefinition: return(TypeOrMethodDefTag.MethodDef);

            default:
                Throw.InvalidArgument_UnexpectedHandleKind(kind);
                return(0);
            }
        }
Example #27
0
        private static MethodDefOrRefTag ToMethodDefOrRefTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.MethodDefinition: return(MethodDefOrRefTag.MethodDef);

            case HandleKind.MemberReference: return(MethodDefOrRefTag.MemberRef);

            default:
                Throw.InvalidArgument_UnexpectedHandleKind(kind);
                return(0);
            }
        }
Example #28
0
        private static HasSemanticsTag ToHasSemanticsTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.EventDefinition: return(HasSemanticsTag.Event);

            case HandleKind.PropertyDefinition: return(HasSemanticsTag.Property);

            default:
                Throw.InvalidArgument_UnexpectedHandleKind(kind);
                return(0);
            }
        }
Example #29
0
        private static MemberForwardedTag ToMemberForwardedTag(HandleKind kind)
        {
            switch (kind)
            {
            case HandleKind.FieldDefinition: return(MemberForwardedTag.Field);

            case HandleKind.MethodDefinition: return(MemberForwardedTag.MethodDef);

            default:
                Throw.InvalidArgument_UnexpectedHandleKind(kind);
                return(0);
            }
        }
Example #30
0
        /// <summary>
        /// Gets the <see cref="TableIndex"/> of the table corresponding to the specified <see cref="HandleKind"/>.
        /// </summary>
        /// <param name="type">Handle type.</param>
        /// <param name="index">Table index.</param>
        /// <returns>True if the handle type corresponds to an Ecma335 or Portable PDB table, false otherwise.</returns>
        public static bool TryGetTableIndex(HandleKind type, out TableIndex index)
        {
            // We don't have a HandleKind for PropertyMap, EventMap, MethodSemantics, *Ptr, AssemblyOS, etc. tables,
            // but one can get ahold of one by creating a handle from a token and getting its Kind.
            if ((int)type < TableCount && ((1UL << (int)type) & (ulong)TableMask.AllTables) != 0)
            {
                index = (TableIndex)type;
                return(true);
            }

            index = 0;
            return(false);
        }
Example #31
0
        private static ResolutionScope ToResolutionScopeTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.ModuleDefinition: return ResolutionScope.Module;
                case HandleKind.ModuleReference: return ResolutionScope.ModuleRef;
                case HandleKind.AssemblyReference: return ResolutionScope.AssemblyRef;
                case HandleKind.TypeReference: return ResolutionScope.TypeRef;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #32
0
        private static HasCustomDebugInformation ToHasCustomDebugInformationTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.MethodDefinition: return HasCustomDebugInformation.MethodDef;
                case HandleKind.FieldDefinition: return HasCustomDebugInformation.Field;
                case HandleKind.TypeReference: return HasCustomDebugInformation.TypeRef;
                case HandleKind.TypeDefinition: return HasCustomDebugInformation.TypeDef;
                case HandleKind.Parameter: return HasCustomDebugInformation.Param;
                case HandleKind.InterfaceImplementation: return HasCustomDebugInformation.InterfaceImpl;
                case HandleKind.MemberReference: return HasCustomDebugInformation.MemberRef;
                case HandleKind.ModuleDefinition: return HasCustomDebugInformation.Module;
                case HandleKind.DeclarativeSecurityAttribute: return HasCustomDebugInformation.DeclSecurity;
                case HandleKind.PropertyDefinition: return HasCustomDebugInformation.Property;
                case HandleKind.EventDefinition: return HasCustomDebugInformation.Event;
                case HandleKind.StandaloneSignature: return HasCustomDebugInformation.StandAloneSig;
                case HandleKind.ModuleReference: return HasCustomDebugInformation.ModuleRef;
                case HandleKind.TypeSpecification: return HasCustomDebugInformation.TypeSpec;
                case HandleKind.AssemblyDefinition: return HasCustomDebugInformation.Assembly;
                case HandleKind.AssemblyReference: return HasCustomDebugInformation.AssemblyRef;
                case HandleKind.AssemblyFile: return HasCustomDebugInformation.File;
                case HandleKind.ExportedType: return HasCustomDebugInformation.ExportedType;
                case HandleKind.ManifestResource: return HasCustomDebugInformation.ManifestResource;
                case HandleKind.GenericParameter: return HasCustomDebugInformation.GenericParam;
                case HandleKind.GenericParameterConstraint: return HasCustomDebugInformation.GenericParamConstraint;
                case HandleKind.MethodSpecification: return HasCustomDebugInformation.MethodSpec;
                case HandleKind.Document: return HasCustomDebugInformation.Document;
                case HandleKind.LocalScope: return HasCustomDebugInformation.LocalScope;
                case HandleKind.LocalVariable: return HasCustomDebugInformation.LocalVariable;
                case HandleKind.LocalConstant: return HasCustomDebugInformation.LocalConstant;
                case HandleKind.ImportScope: return HasCustomDebugInformation.ImportScope;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #33
0
        private static CustomAttributeType ToCustomAttributeTypeTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.MethodDefinition: return CustomAttributeType.MethodDef;
                case HandleKind.MemberReference: return CustomAttributeType.MemberRef;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #34
0
        private static HasDeclSecurity ToHasDeclSecurityTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.TypeDefinition: return HasDeclSecurity.TypeDef;
                case HandleKind.MethodDefinition: return HasDeclSecurity.MethodDef;
                case HandleKind.AssemblyDefinition: return HasDeclSecurity.Assembly;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #35
0
        private static HasSemantics ToHasSemanticsTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.EventDefinition: return HasSemantics.Event;
                case HandleKind.PropertyDefinition: return HasSemantics.Property;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #36
0
        /// <summary>
        /// Gets the <see cref="HeapIndex"/> of the heap corresponding to the specified <see cref="HandleKind"/>.
        /// </summary>
        /// <param name="type">Handle type.</param>
        /// <param name="index">Heap index.</param>
        /// <returns>True if the handle type corresponds to an Ecma335 heap, false otherwise.</returns>
        public static bool TryGetHeapIndex(HandleKind type, out HeapIndex index)
        {
            switch (type)
            {
                case HandleKind.UserString:
                    index = HeapIndex.UserString;
                    return true;

                case HandleKind.String:
                case HandleKind.NamespaceDefinition:
                    index = HeapIndex.String;
                    return true;

                case HandleKind.Blob:
                    index = HeapIndex.Blob;
                    return true;

                case HandleKind.Guid:
                    index = HeapIndex.Guid;
                    return true;

                default:
                    index = 0;
                    return false;
            }
        }
Example #37
0
        private static MethodDefOrRef ToMethodDefOrRefTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.MethodDefinition: return MethodDefOrRef.MethodDef;
                case HandleKind.MemberReference: return MethodDefOrRef.MemberRef;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #38
0
        private static MemberRefParent ToMemberRefParentTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.TypeDefinition: return MemberRefParent.TypeDef;
                case HandleKind.TypeReference: return MemberRefParent.TypeRef;
                case HandleKind.ModuleReference: return MemberRefParent.ModuleRef;
                case HandleKind.MethodDefinition: return MemberRefParent.MethodDef;
                case HandleKind.TypeSpecification: return MemberRefParent.TypeSpec;

                default:
                    throw new ArgumentException($"Unexpected kind of handle: {kind}");
            }
        }
Example #39
0
        private static ResolutionScope ToResolutionScopeTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.ModuleDefinition: return ResolutionScope.Module;
                case HandleKind.ModuleReference: return ResolutionScope.ModuleRef;
                case HandleKind.AssemblyReference: return ResolutionScope.AssemblyRef;
                case HandleKind.TypeReference: return ResolutionScope.TypeRef;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #40
0
        private static TypeOrMethodDef ToTypeOrMethodDefTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.TypeDefinition: return TypeOrMethodDef.TypeDef;
                case HandleKind.MethodDefinition: return TypeOrMethodDef.MethodDef;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #41
0
        private static TypeDefOrRefOrSpec ToTypeDefOrRefOrSpecTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.TypeDefinition: return TypeDefOrRefOrSpec.TypeDef;
                case HandleKind.TypeReference: return TypeDefOrRefOrSpec.TypeRef;
                case HandleKind.TypeSpecification: return TypeDefOrRefOrSpec.TypeSpec;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #42
0
        /// <summary>
        /// Gets the <see cref="TableIndex"/> of the table corresponding to the specified <see cref="HandleKind"/>.
        /// </summary>
        /// <param name="type">Handle type.</param>
        /// <param name="index">Table index.</param>
        /// <returns>True if the handle type corresponds to an Ecma335 or Portable PDB table, false otherwise.</returns>
        public static bool TryGetTableIndex(HandleKind type, out TableIndex index)
        {
            // We don't have a HandleKind for PropertyMap, EventMap, MethodSemantics, *Ptr, AssemblyOS, etc. tables, 
            // but one can get ahold of one by creating a handle from a token and getting its Kind.
            if ((int)type < TableCount && ((1UL << (int)type) & (ulong)TableMask.AllTables) != 0)
            {
                index = (TableIndex)type;
                return true;
            }

            index = 0;
            return false;
        }
Example #43
0
        private static MemberRefParent ToMemberRefParentTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.TypeDefinition: return MemberRefParent.TypeDef;
                case HandleKind.TypeReference: return MemberRefParent.TypeRef;
                case HandleKind.ModuleReference: return MemberRefParent.ModuleRef;
                case HandleKind.MethodDefinition: return MemberRefParent.MethodDef;
                case HandleKind.TypeSpecification: return MemberRefParent.TypeSpec;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #44
0
        private static Implementation ToImplementationTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.AssemblyFile: return Implementation.File;
                case HandleKind.AssemblyReference: return Implementation.AssemblyRef;
                case HandleKind.ExportedType: return Implementation.ExportedType;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #45
0
        private static MemberForwarded ToMemberForwardedTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.FieldDefinition: return MemberForwarded.Field;
                case HandleKind.MethodDefinition: return MemberForwarded.MethodDef;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #46
0
        private static HasFieldMarshal ToHasFieldMarshalTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.FieldDefinition: return HasFieldMarshal.Field;
                case HandleKind.Parameter: return HasFieldMarshal.Param;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #47
0
        /// <summary>
        /// Gets the <see cref="TableIndex"/> of the table corresponding to the specified <see cref="HandleKind"/>.
        /// </summary>
        /// <param name="type">Handle type.</param>
        /// <param name="index">Table index.</param>
        /// <returns>True if the handle type corresponds to an Ecma335 table, false otherwise.</returns>
        public static bool TryGetTableIndex(HandleKind type, out TableIndex index)
        {
            if ((int)type < TableIndexExtensions.Count)
            {
                index = (TableIndex)type;
                return true;
            }

            index = 0;
            return false;
        }
Example #48
0
        private static HasConstant ToHasConstantTag(HandleKind kind)
        {
            switch (kind)
            {
                case HandleKind.FieldDefinition: return HasConstant.Field;
                case HandleKind.Parameter: return HasConstant.Param;
                case HandleKind.PropertyDefinition: return HasConstant.Property;

                default:
                    throw UnexpectedHandleKind(kind);
            }
        }
Example #49
0
 private static Exception UnexpectedHandleKind(HandleKind kind)
 {
     return new ArgumentException(SR.Format(SR.UnexpectedHandleKind, kind));
 }