Ejemplo n.º 1
0
        protected override bool TryGetItemByName(string name, out EnvDTE.CodeElement element)
        {
            var node = LookupNode();

            // Inherits statements
            foreach (var child in CodeModelService.GetInheritsNodes(node))
            {
                CodeModelService.GetInheritsNamespaceAndOrdinal(node, child, out var childName, out var ordinal);
                if (childName == name)
                {
                    element = FileCodeModel.GetOrCreateCodeElement <EnvDTE.CodeElement>(child);
                    return(true);
                }
            }

            // Implements statements
            foreach (var child in CodeModelService.GetImplementsNodes(node))
            {
                CodeModelService.GetImplementsNamespaceAndOrdinal(node, child, out var childName, out var ordinal);
                if (childName == name)
                {
                    element = FileCodeModel.GetOrCreateCodeElement <EnvDTE.CodeElement>(child);
                    return(true);
                }
            }

            element = null;
            return(false);
        }
Ejemplo n.º 2
0
        protected override bool TryGetItemByIndex(int index, out EnvDTE.CodeElement element)
        {
            var node = LookupNode();

            var currentIndex = 0;

            // Inherits statements
            var inheritsNodes     = CodeModelService.GetInheritsNodes(node);
            var inheritsNodeCount = inheritsNodes.Count();

            if (index < currentIndex + inheritsNodeCount)
            {
                var child = inheritsNodes.ElementAt(index - currentIndex);
                element = FileCodeModel.GetOrCreateCodeElement <EnvDTE.CodeElement>(child);
                return(true);
            }

            currentIndex += inheritsNodeCount;

            // Implements statements
            var implementsNodes     = CodeModelService.GetImplementsNodes(node);
            var implementsNodeCount = implementsNodes.Count();

            if (index < currentIndex + implementsNodeCount)
            {
                var child = implementsNodes.ElementAt(index - currentIndex);
                element = FileCodeModel.GetOrCreateCodeElement <EnvDTE.CodeElement>(child);
                return(true);
            }

            element = null;
            return(false);
        }
        internal override Snapshot CreateSnapshot()
        {
            var node          = LookupNode();
            var parentElement = (AbstractCodeElement)this.Parent;

            var nodesBuilder = ImmutableArray.CreateBuilder <SyntaxNode>();

            nodesBuilder.AddRange(CodeModelService.GetInheritsNodes(node));
            nodesBuilder.AddRange(CodeModelService.GetImplementsNodes(node));

            return(new NodeSnapshot(this.State, _fileCodeModel, node, parentElement, nodesBuilder.ToImmutable()));
        }