Ejemplo n.º 1
0
        private SDType CreateSDType(INamedTypeSymbol typeSymbol, SDNamespace sdNamespace)
        {
            var sdType = new SDType(typeSymbol.GetIdentifier(), typeSymbol.Name, sdNamespace)
            {
                Accessibility     = typeSymbol.DeclaredAccessibility.ToString().ToLower(),
                IsAbstract        = typeSymbol.IsAbstract,
                IsReferenceType   = typeSymbol.IsReferenceType,
                IsSealed          = typeSymbol.IsSealed,
                IsStatic          = typeSymbol.IsStatic,
                IsProjectStranger = false,
                Kind = typeSymbol.TypeKind.ToString().ToLower()
            };

            foreach (var reference in typeSymbol.DeclaringSyntaxReferences.ToList())
            {
                var region = new SDRegion
                {
                    Start    = reference.Span.Start,
                    End      = reference.Span.End,
                    Filename = reference.SyntaxTree.FilePath
                };
                sdType.Regions.Add(region);
            }
            return(sdType);
        }
Ejemplo n.º 2
0
        private SDType CreateSDType(ITypeSymbol typeSymbol, bool isProjectStranger)
        {
            SDNamespace sdNamespace = null;

            if (typeSymbol is IArrayTypeSymbol)
            {
                sdNamespace = ParserOptions.SDRepository.GetNamespaceByIdentifier(((IArrayTypeSymbol)typeSymbol).ElementType.ContainingNamespace.GetIdentifier());
                sdNamespace = sdNamespace ?? new SDNamespace(((IArrayTypeSymbol)typeSymbol).ElementType.ContainingNamespace.GetIdentifier())
                {
                    IsProjectStranger = true
                };
            }
            else
            {
                sdNamespace = ParserOptions.SDRepository.GetNamespaceByIdentifier(typeSymbol.ContainingNamespace.GetIdentifier());
                sdNamespace = sdNamespace ?? new SDNamespace(typeSymbol.ContainingNamespace.GetIdentifier())
                {
                    IsProjectStranger = true
                };
            }

            var sdType = new SDType(typeSymbol.GetIdentifier(), typeSymbol.Name, sdNamespace)
            {
                Accessibility     = typeSymbol.DeclaredAccessibility.ToString().ToLower(),
                IsAbstract        = typeSymbol.IsAbstract,
                IsReferenceType   = typeSymbol.IsReferenceType,
                IsSealed          = typeSymbol.IsSealed,
                IsStatic          = typeSymbol.IsStatic,
                IsProjectStranger = isProjectStranger,
                Kind = typeSymbol.TypeKind.ToString().ToLower()
            };

            var declaringReferences = !isProjectStranger?typeSymbol.DeclaringSyntaxReferences.ToList() : new List <SyntaxReference>();

            foreach (var reference in declaringReferences)
            {
                var region = new SDRegion
                {
                    Start    = reference.Span.Start,
                    End      = reference.Span.End,
                    Filename = reference.SyntaxTree.FilePath
                };
                sdType.Regions.Add(region);
            }

            ParserOptions.SDRepository.AddType(sdType);

            return(sdType);
        }
Ejemplo n.º 3
0
        private List <SDRegion> GetRegions(INamedTypeSymbol typeSymbol)
        {
            var regions = new List <SDRegion>();

            foreach (var reference in typeSymbol.DeclaringSyntaxReferences.ToList())
            {
                var region = new SDRegion
                {
                    Start     = reference.Span.Start,
                    End       = reference.Span.End,
                    StartLine = reference.SyntaxTree.GetLineSpan(reference.Span).StartLinePosition.Line + 1,
                    EndLine   = reference.SyntaxTree.GetLineSpan(reference.Span).EndLinePosition.Line + 1,
                    FilePath  = reference.SyntaxTree.FilePath,
                    Filename  = Path.GetFileName(reference.SyntaxTree.FilePath),
                    Content   = File.ReadAllText(reference.SyntaxTree.FilePath)
                };
                regions.Add(region);
            }
            return(regions);
        }