Beispiel #1
0
        internal MetadataProperty(MetadataModule module, PropertyDefinitionHandle handle)
        {
            Debug.Assert(module != null);
            Debug.Assert(!handle.IsNil);
            this.module         = module;
            this.propertyHandle = handle;

            var metadata  = module.metadata;
            var prop      = metadata.GetPropertyDefinition(handle);
            var accessors = prop.GetAccessors();

            getter = module.GetDefinition(accessors.Getter);
            setter = module.GetDefinition(accessors.Setter);
            name   = metadata.GetString(prop.Name);
            // Maybe we should defer the calculation of symbolKind?
            if (DetermineIsIndexer(name))
            {
                symbolKind = SymbolKind.Indexer;
            }
            else if (name.IndexOf('.') >= 0)
            {
                // explicit interface implementation
                var interfaceProp = this.ExplicitlyImplementedInterfaceMembers.FirstOrDefault() as IProperty;
                symbolKind = interfaceProp?.SymbolKind ?? SymbolKind.Property;
            }
            else
            {
                symbolKind = SymbolKind.Property;
            }
        }
        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);
            }
        }