Пример #1
0
        public Symbol FindSymbol(string name, Symbol context, SymbolFilter filter)
        {
            Debug.Assert(string.IsNullOrEmpty(name) == false);

            Symbol symbol = null;

            if (this.IsAnonymousType && (filter & SymbolFilter.Types) == 0)
            {
                var anonymousProperty = new PropertySymbol(name, this, this);
                anonymousProperty.SetNameCasing(preserveCase: true);
                return(anonymousProperty);
            }

            if ((filter & SymbolFilter.Types) != 0)
            {
                symbol = GetNestedType(name, context, filter)
                         ?? GetGenericParamaterType(name, context, filter);
            }

            if (symbol == null && (filter & SymbolFilter.Members) != 0)
            {
                SymbolFilter baseFilter = filter | SymbolFilter.ExcludeParent;

                symbol = GetMember(name)
                         ?? FindSymbolFromBase(name, context, symbol, baseFilter);

                if (symbol != null && symbol.MatchFilter(filter) == false)
                {
                    symbol = null;
                }
            }

            if (symbol == null && !filter.HasFlag(SymbolFilter.ExcludeParent))
            {
                if (parentSymbolTable != null)
                {
                    symbol = parentSymbolTable.FindSymbol(name, context, filter);
                }
                else if (context?.Parent is ISymbolTable symbolTable)
                {
                    symbolTable.FindSymbol(name, context, filter);
                }
            }

            return(symbol);
        }
Пример #2
0
        private MemberSymbol CreateGenericMember(MemberSymbol templateMember, IList <TypeSymbol> typeArguments)
        {
            TypeSymbol parentType = (TypeSymbol)templateMember.Parent;
            TypeSymbol instanceAssociatedType;

            if (templateMember.AssociatedType.Type == SymbolType.GenericParameter)
            {
                GenericParameterSymbol genericParameter = (GenericParameterSymbol)templateMember.AssociatedType;
                instanceAssociatedType = typeArguments[genericParameter.Index];
            }
            else
            {
                instanceAssociatedType = typeArguments[0];
            }

            if (templateMember.Type == SymbolType.Indexer)
            {
                IndexerSymbol templateIndexer = (IndexerSymbol)templateMember;
                IndexerSymbol instanceIndexer = new IndexerSymbol(parentType, instanceAssociatedType);

                if (templateIndexer.UseScriptIndexer)
                {
                    instanceIndexer.SetScriptIndexer();
                }

                instanceIndexer.SetVisibility(templateIndexer.Visibility);

                return(instanceIndexer);
            }

            if (templateMember.Type == SymbolType.Property)
            {
                PropertySymbol templateProperty = (PropertySymbol)templateMember;
                PropertySymbol instanceProperty =
                    new PropertySymbol(templateProperty.Name, parentType, instanceAssociatedType);

                if (templateProperty.IsTransformed)
                {
                    instanceProperty.SetTransformedName(templateProperty.GeneratedName);
                }

                instanceProperty.SetNameCasing(templateProperty.IsCasePreserved);
                instanceProperty.SetVisibility(templateProperty.Visibility);

                return(instanceProperty);
            }

            if (templateMember.Type == SymbolType.Field)
            {
                FieldSymbol templateField = (FieldSymbol)templateMember;
                FieldSymbol instanceField = new FieldSymbol(templateField.Name, parentType, instanceAssociatedType);

                if (templateField.IsTransformed)
                {
                    instanceField.SetTransformName(templateField.GeneratedName);
                }

                instanceField.SetNameCasing(templateField.IsCasePreserved);
                instanceField.SetVisibility(templateField.Visibility);

                return(instanceField);
            }

            if (templateMember.Type == SymbolType.Method)
            {
                MethodSymbol templateMethod = (MethodSymbol)templateMember;
                MethodSymbol instanceMethod = new MethodSymbol(templateMethod.Name, parentType, instanceAssociatedType);

                if (templateMethod.IsAliased)
                {
                    instanceMethod.SetTransformedName(templateMethod.TransformName);
                }
                else if (templateMethod.IsTransformed)
                {
                    instanceMethod.SetTransformedName(templateMethod.GeneratedName);
                }

                if (templateMethod.SkipGeneration)
                {
                    instanceMethod.SetSkipGeneration();
                }

                if (templateMethod.InterfaceMember != null)
                {
                    instanceMethod.SetInterfaceMember(templateMethod.InterfaceMember);
                }

                instanceMethod.SetNameCasing(templateMethod.IsCasePreserved);
                instanceMethod.SetVisibility(templateMethod.Visibility);

                return(instanceMethod);
            }

            Debug.Fail("Unexpected generic member '" + templateMember.Name + " on type '" +
                       ((TypeSymbol)templateMember.Parent).FullName + "'.");

            return(null);
        }