Пример #1
0
        private const string ReservedIdentifiers = "nameof"; //separated by comma

        public Reference(SemanticModel semanticModel, ExpressionSyntax expressionSyntax)
        {
            Symbol = GetSymbol(semanticModel, expressionSyntax);

            if (Symbol == null && !Reserved && !ExplicitlyDynamic && !Anonymous)
            {
                throw new CodeAnalysisException(
                          CodeAnalysisError.TypeNotResolved(expressionSyntax.ToString()));
            }
            else if (Reserved || ExplicitlyDynamic || Anonymous)
            {
                return;
            }

            Name      = Symbol.Name;
            Namespace = Symbol.ContainingNamespace.ToString();

            if (Symbol.Kind == SymbolKind.Field ||
                Symbol.Kind == SymbolKind.Local ||
                Symbol.Kind == SymbolKind.Property ||
                Symbol.Kind == SymbolKind.Parameter)
            {
                var typeInfo = semanticModel.GetTypeInfo(expressionSyntax);

                if (typeInfo.ConvertedType == null)
                {
                    throw new CodeAnalysisException(
                              CodeAnalysisError.TypeNotResolved(expressionSyntax.ToString()));
                }

                Symbol = typeInfo.ConvertedType.ContainingSymbol;

                if (Symbol is IArrayTypeSymbol arrayTypeSymbol)
                {
                    Symbol = arrayTypeSymbol.ElementType;
                }

                Name      = typeInfo.Type.Name;
                Namespace = typeInfo.ConvertedType.ContainingNamespace.ToString();
            }
            else if (Symbol.Kind == SymbolKind.Method)
            {
                var refSymbol = Symbol;

                while (refSymbol.Kind == SymbolKind.Method && refSymbol.ContainingSymbol != null)
                {
                    refSymbol = refSymbol.ContainingSymbol;
                }

                Name = refSymbol.Name;
            }
        }
Пример #2
0
        private StructureType GetStructureType(
            MemberDeclarationSyntax member)
        {
            if (member is ClassDeclarationSyntax)
            {
                return(StructureType.Class);
            }
            else if (member is InterfaceDeclarationSyntax)
            {
                return(StructureType.Interface);
            }
            else if (member is EnumDeclarationSyntax)
            {
                return(StructureType.Enum);
            }

            var namespaceIdentifier = ((BaseTypeDeclarationSyntax)member).Identifier.ValueText;

            throw new CodeAnalysisException(
                      CodeAnalysisError.StructureTypeNotFound(namespaceIdentifier));
        }
Пример #3
0
            public Context(IDslSyntaxProvider dslSyntaxProvider)
            {
                DslSyntaxProvider         = dslSyntaxProvider;
                CreatedTime               = DateTime.Now;
                DslSyntaxLastModifiedTime = dslSyntaxProvider.GetLastModifiedTime();

                var(dslSyntax, dslSyntaxError) = LoadDslSyntax(dslSyntaxProvider);
                if (dslSyntaxError == null)
                {
                    DslSyntax        = dslSyntax;
                    DslDocumentation = dslSyntaxProvider.LoadDocumentation();
                    Keywords         = ExtractKeywords(dslSyntax);
                }
                else
                {
                    InitializationError = new CodeAnalysisError {
                        Message = dslSyntaxError
                    };
                    DslDocumentation = new DslDocumentation {
                        Concepts = new Dictionary <string, ConceptDocumentation>()
                    };
                    Keywords = new Dictionary <string, ConceptType[]>();
                }
            }