private FieldSymbol BuildPropertyAsField(PropertyDeclarationNode propertyNode, TypeSymbol typeSymbol) { AttributeNode intrinsicPropertyAttribute = AttributeNode.FindAttribute(propertyNode.Attributes, "IntrinsicProperty"); if (intrinsicPropertyAttribute == null) { return null; } TypeSymbol fieldType = typeSymbol.SymbolSet.ResolveType(propertyNode.Type, _symbolTable, typeSymbol); Debug.Assert(fieldType != null); if (fieldType != null) { FieldSymbol symbol = new FieldSymbol(propertyNode.Name, typeSymbol, fieldType); BuildMemberDetails(symbol, typeSymbol, propertyNode, propertyNode.Attributes); string scriptAlias = GetAttributeValue(propertyNode.Attributes, "ScriptAlias"); if (scriptAlias != null) { symbol.SetAlias(scriptAlias); } return symbol; } return null; }
private void ImportProperties(TypeSymbol typeSymbol) { TypeDefinition type = (TypeDefinition)typeSymbol.MetadataReference; foreach (PropertyDefinition property in type.Properties) { if (property.IsSpecialName) { continue; } if (property.GetMethod == null) { continue; } if (property.GetMethod.IsPrivate || property.GetMethod.IsAssembly || property.GetMethod.IsFamilyAndAssembly) { continue; } string propertyName = property.Name; bool preserveCase = MetadataHelpers.ShouldPreserveCase(property); bool intrinsicProperty = MetadataHelpers.ShouldTreatAsIntrinsicProperty(property); TypeSymbol propertyType = ResolveType(property.PropertyType); if (propertyType == null) { continue; } PropertySymbol propertySymbol = null; if (property.Parameters.Count != 0) { IndexerSymbol indexerSymbol = new IndexerSymbol(typeSymbol, propertyType); ImportMemberDetails(indexerSymbol, property.GetMethod, property); if (intrinsicProperty) { indexerSymbol.SetIntrinsic(); } propertySymbol = indexerSymbol; propertySymbol.SetNameCasing(preserveCase); } else { if (intrinsicProperty) { // Properties marked with this attribute are to be thought of as // fields. If they are read-only, the C# compiler will enforce that, // so we don't have to worry about making them read-write via a field // instead of a property FieldSymbol fieldSymbol = new FieldSymbol(propertyName, typeSymbol, propertyType); ImportMemberDetails(fieldSymbol, property.GetMethod, property); string alias = MetadataHelpers.GetScriptAlias(property); if (String.IsNullOrEmpty(alias) == false) { fieldSymbol.SetAlias(alias); } typeSymbol.AddMember(fieldSymbol); } else { propertySymbol = new PropertySymbol(propertyName, typeSymbol, propertyType); ImportMemberDetails(propertySymbol, property.GetMethod, property); } } if (propertySymbol != null) { SymbolImplementationFlags implFlags = SymbolImplementationFlags.Regular; if (property.SetMethod == null) { implFlags |= SymbolImplementationFlags.ReadOnly; } if (property.GetMethod.IsAbstract) { implFlags |= SymbolImplementationFlags.Abstract; } propertySymbol.SetImplementationState(implFlags); typeSymbol.AddMember(propertySymbol); } } }