Exemple #1
0
        private ITypeExtraction GetContainingType()
        {
            SymbolInfo symbol = _model.GetSymbolInfo(_node);

            if (symbol.Symbol?.ContainingType?.ContainingType != null)
            {
                return(TypeExtraction.CreateTypeExtraction(_registry, symbol.Symbol.ContainingType.Name));
            }
            return(null);
        }
        public static IEnumerable <ITypeExtraction> Reversed(DeclarationRegistry registry, string name, Func <ITypeExtraction, IEnumerable <ITypeExtraction> > getter)
        {
            IEnumerable <TypeDeclarationSyntax> declarations = registry.Types;

            foreach (TypeDeclarationSyntax declaration in declarations)
            {
                ITypeExtraction extraction = TypeExtraction.CreateTypeExtraction(registry, declaration.Identifier.ValueText);
                foreach (ITypeExtraction extr in getter(extraction))
                {
                    if (extr.Name == name)
                    {
                        yield return(extraction);
                    }
                }
            }
        }
        public IEnumerable <ITypeExtraction> GetParents()
        {
            INamedTypeSymbol symbol = (INamedTypeSymbol)_model.GetDeclaredSymbol(_node);

            foreach (INamedTypeSymbol interfaceSymbol in symbol.Interfaces)
            {
                var extraction = TypeExtraction.CreateTypeExtraction(_registry, interfaceSymbol.Name);
                if (extraction != null)
                {
                    yield return(extraction);
                }
            }

            string parentName = symbol.BaseType?.Name;

            if (parentName != null && parentName != "Object")
            {
                var extraction = TypeExtraction.CreateTypeExtraction(_registry, symbol.BaseType.Name);
                if (extraction != null)
                {
                    yield return(extraction);
                }
            }
        }
        public IEnumerable <ITypeExtraction> GetReferenced()
        {
            foreach (PropertyDeclarationSyntax propDecl in _node.DescendantNodes().OfType <PropertyDeclarationSyntax>())
            {
                IPropertySymbol propSymbol = _model.GetDeclaredSymbol(propDecl);
                if (propSymbol != null)
                {
                    ITypeExtraction extraction = TypeExtraction.CreateTypeExtraction(_registry, propSymbol.Type.Name);
                    if (extraction != null)
                    {
                        yield return(extraction);
                    }
                    ;
                }

                if (propDecl.Type is GenericNameSyntax typeSyntax)
                {
                    foreach (var tArg in typeSyntax.TypeArgumentList.Arguments)
                    {
                        TypeInfo        argSymbol  = _model.GetTypeInfo(tArg);
                        ITypeExtraction extraction = TypeExtraction.CreateTypeExtraction(_registry, argSymbol.Type.Name);
                        if (extraction != null)
                        {
                            yield return(extraction);
                        }
                    }
                }
            }

            foreach (FieldDeclarationSyntax fieldDecl in _node.DescendantNodes().OfType <FieldDeclarationSyntax>())
            {
                string     childName = null;
                TypeSyntax fieldType = fieldDecl.Declaration.Type;

                if (fieldType is GenericNameSyntax talSyntax)
                {
                    childName = talSyntax.Identifier.ValueText;
                    // generic type parameters
                    foreach (var tArg in talSyntax.TypeArgumentList.Arguments)
                    {
                        TypeInfo        argSymbol  = _model.GetTypeInfo(tArg);
                        ITypeExtraction extraction = TypeExtraction.CreateTypeExtraction(_registry, argSymbol.Type.Name);
                        if (extraction != null)
                        {
                            yield return(extraction);
                        }
                    }
                }
                else if (fieldType is IdentifierNameSyntax inSyntax)
                {
                    childName = inSyntax.Identifier.ValueText;
                }

                if (childName != null)
                {
                    ITypeExtraction extraction = TypeExtraction.CreateTypeExtraction(_registry, childName);
                    if (extraction != null)
                    {
                        yield return(extraction);
                    }
                }
            }
        }
Exemple #5
0
 private ITypeExtraction GetSymbolExtraction(ITypeSymbol symbol)
 => TypeExtraction.CreateTypeExtraction(_registry, symbol.Name);