Beispiel #1
0
        internal MetadataMethod(MetadataModule module, MethodDefinitionHandle handle)
        {
            Debug.Assert(module != null);
            Debug.Assert(!handle.IsNil);
            this.module = module;
            this.handle = handle;
            var metadata = module.metadata;
            var def      = metadata.GetMethodDefinition(handle);

            this.attributes = def.Attributes;

            this.symbolKind = SymbolKind.Method;
            var(accessorOwner, semanticsAttribute) = module.PEFile.MethodSemanticsLookup.GetSemantics(handle);
            const MethodAttributes finalizerAttributes = (MethodAttributes.Virtual | MethodAttributes.Family | MethodAttributes.HideBySig);

            if (semanticsAttribute != 0)
            {
                this.symbolKind    = SymbolKind.Accessor;
                this.accessorOwner = accessorOwner;
                this.AccessorKind  = semanticsAttribute;
            }
            else if ((attributes & (MethodAttributes.SpecialName | MethodAttributes.RTSpecialName)) != 0)
            {
                string name = this.Name;
                if (name == ".cctor" || name == ".ctor")
                {
                    this.symbolKind = SymbolKind.Constructor;
                }
                else if (name.StartsWith("op_", StringComparison.Ordinal))
                {
                    this.symbolKind = SymbolKind.Operator;
                }
            }
            else if ((attributes & finalizerAttributes) == finalizerAttributes)
            {
                string name = this.Name;
                if (name == "Finalize" && Parameters.Count == 0)
                {
                    this.symbolKind = SymbolKind.Destructor;
                }
            }
            this.typeParameters    = MetadataTypeParameter.Create(module, this, def.GetGenericParameters());
            this.IsExtensionMethod = (attributes & MethodAttributes.Static) == MethodAttributes.Static &&
                                     (module.TypeSystemOptions & TypeSystemOptions.ExtensionMethods) == TypeSystemOptions.ExtensionMethods &&
                                     def.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.Extension);
        }
Beispiel #2
0
        internal MetadataTypeDefinition(MetadataModule module, TypeDefinitionHandle handle)
        {
            Debug.Assert(module != null);
            Debug.Assert(!handle.IsNil);
            this.module = module;
            this.handle = handle;
            var metadata = module.metadata;
            var td       = metadata.GetTypeDefinition(handle);

            this.attributes   = td.Attributes;
            this.fullTypeName = td.GetFullTypeName(metadata);
            // Find DeclaringType + KnownTypeCode:
            if (fullTypeName.IsNested)
            {
                this.DeclaringTypeDefinition = module.GetDefinition(td.GetDeclaringType());

                // Create type parameters:
                this.TypeParameters = MetadataTypeParameter.Create(module, this.DeclaringTypeDefinition, this, td.GetGenericParameters());
            }
            else
            {
                // Create type parameters:
                this.TypeParameters = MetadataTypeParameter.Create(module, this, td.GetGenericParameters());

                var topLevelTypeName = fullTypeName.TopLevelTypeName;
                for (int i = 0; i < KnownTypeReference.KnownTypeCodeCount; i++)
                {
                    var ktr = KnownTypeReference.Get((KnownTypeCode)i);
                    if (ktr != null && ktr.TypeName == topLevelTypeName)
                    {
                        this.KnownTypeCode = (KnownTypeCode)i;
                        break;
                    }
                }
            }
            // Find type kind:
            if ((attributes & TypeAttributes.ClassSemanticsMask) == TypeAttributes.Interface)
            {
                this.Kind = TypeKind.Interface;
            }
            else if (td.IsEnum(metadata, out var underlyingType))
            {
                this.Kind = TypeKind.Enum;
                this.EnumUnderlyingType = module.Compilation.FindType(underlyingType.ToKnownTypeCode());
            }
            else if (td.IsValueType(metadata))
            {
                if (KnownTypeCode == KnownTypeCode.Void)
                {
                    this.Kind = TypeKind.Void;
                }
                else
                {
                    this.Kind        = TypeKind.Struct;
                    this.IsByRefLike = td.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.IsByRefLike);
                    this.IsReadOnly  = td.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.IsReadOnly);
                }
            }
            else if (td.IsDelegate(metadata))
            {
                this.Kind = TypeKind.Delegate;
            }
            else
            {
                this.Kind = TypeKind.Class;
                this.HasExtensionMethods = this.IsStatic &&
                                           (module.TypeSystemOptions & TypeSystemOptions.ExtensionMethods) == TypeSystemOptions.ExtensionMethods &&
                                           td.GetCustomAttributes().HasKnownAttribute(metadata, KnownAttribute.Extension);
            }
        }