示例#1
0
        private PropertySymbol BuildProperty(PropertyDeclarationNode propertyNode, TypeSymbol typeSymbol)
        {
            TypeSymbol propertyType = typeSymbol.SymbolSet.ResolveType(propertyNode.Type, _symbolTable, typeSymbol);

            Debug.Assert(propertyType != null);

            if (propertyType != null)
            {
                PropertySymbol property = new PropertySymbol(propertyNode.Name, typeSymbol, propertyType);
                BuildMemberDetails(property, typeSymbol, propertyNode, propertyNode.Attributes);

                SymbolImplementationFlags implFlags = SymbolImplementationFlags.Regular;
                if (propertyNode.SetAccessor == null)
                {
                    implFlags |= SymbolImplementationFlags.ReadOnly;
                }
                if ((propertyNode.Modifiers & Modifiers.Abstract) != 0)
                {
                    implFlags |= SymbolImplementationFlags.Abstract;
                }
                else if ((propertyNode.Modifiers & Modifiers.Override) != 0)
                {
                    implFlags |= SymbolImplementationFlags.Override;
                }
                property.SetImplementationState(implFlags);

                property.AddParameter(new ParameterSymbol("value", property, propertyType, ParameterMode.In));

                return(property);
            }

            return(null);
        }
示例#2
0
        private IndexerSymbol BuildIndexer(IndexerDeclarationNode indexerNode, TypeSymbol typeSymbol)
        {
            TypeSymbol indexerType = typeSymbol.SymbolSet.ResolveType(indexerNode.Type, _symbolTable, typeSymbol);

            Debug.Assert(indexerType != null);

            if (indexerType != null)
            {
                IndexerSymbol indexer = new IndexerSymbol(typeSymbol, indexerType);
                BuildMemberDetails(indexer, typeSymbol, indexerNode, indexerNode.Attributes);

                if (AttributeNode.FindAttribute(indexerNode.Attributes, "IntrinsicProperty") != null)
                {
                    indexer.SetIntrinsic();
                }

                SymbolImplementationFlags implFlags = SymbolImplementationFlags.Regular;
                if (indexerNode.SetAccessor == null)
                {
                    implFlags |= SymbolImplementationFlags.ReadOnly;
                }
                if ((indexerNode.Modifiers & Modifiers.Abstract) != 0)
                {
                    implFlags |= SymbolImplementationFlags.Abstract;
                }
                else if ((indexerNode.Modifiers & Modifiers.Override) != 0)
                {
                    implFlags |= SymbolImplementationFlags.Override;
                }

                indexer.SetImplementationState(implFlags);

                Debug.Assert(indexerNode.Parameters.Count != 0);
                foreach (ParameterNode parameterNode in indexerNode.Parameters)
                {
                    ParameterSymbol paramSymbol = BuildParameter(parameterNode, indexer);
                    if (paramSymbol != null)
                    {
                        paramSymbol.SetParseContext(parameterNode);
                        indexer.AddParameter(paramSymbol);
                    }
                }

                indexer.AddParameter(new ParameterSymbol("value", indexer, indexerType, ParameterMode.In));

                return(indexer);
            }

            return(null);
        }
示例#3
0
 public void SetImplementationState(SymbolImplementationFlags implementationFlags)
 {
     Debug.Assert(_implementationFlags == SymbolImplementationFlags.Regular);
     _implementationFlags = implementationFlags;
 }
示例#4
0
        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   scriptField  = MetadataHelpers.ShouldTreatAsScriptField(property);

                // TODO: Why are we ignoring the other bits...
                // bool dummyPreserveName;
                // bool preserveCase;
                // string dummyName = MetadataHelpers.GetScriptName(property, out dummyPreserveName, out preserveCase);

                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 (scriptField)
                    {
                        indexerSymbol.SetScriptIndexer();
                    }

                    propertySymbol = indexerSymbol;
                    // propertySymbol.SetNameCasing(preserveCase);
                }
                else
                {
                    if (scriptField)
                    {
                        // 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 transformedName = MetadataHelpers.GetTransformedName(property);

                        if (string.IsNullOrEmpty(transformedName) == false)
                        {
                            fieldSymbol.SetTransformName(transformedName);
                        }

                        typeSymbol.AddMember(fieldSymbol);
                    }
                    else
                    {
                        propertySymbol = new PropertySymbol(propertyName, typeSymbol, propertyType);
                        ImportMemberDetails(propertySymbol, property.GetMethod, property);
                        propertySymbol.SetNameCasing(true);

                        string transformedName = MetadataHelpers.GetTransformedName(property.GetMethod);

                        if (string.IsNullOrEmpty(transformedName) == false)
                        {
                            propertySymbol.SetTransformedName(transformedName);
                        }
                    }
                }

                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);
                }
            }
        }
示例#5
0
 public void SetImplementationState(SymbolImplementationFlags implementationFlags)
 {
     Debug.Assert(_implementationFlags == SymbolImplementationFlags.Regular);
     _implementationFlags = implementationFlags;
 }