예제 #1
0
        private EnvDTE.CodeElement GetAttributeArgumentForCodeModelEvent(CodeModelEvent codeModelEvent, EnvDTE.CodeElements parentAttributeArguments, object parentElement)
        {
            if (parentAttributeArguments == null)
            {
                return(null);
            }

            SyntaxNode attributeNode;
            int        ordinal;

            CodeModelService.GetAttributeArgumentParentAndIndex(codeModelEvent.Node, out attributeNode, out ordinal);

            if (codeModelEvent.Type == CodeModelEventType.Remove)
            {
                var parentCodeElement = ComAggregate.TryGetManagedObject <CodeAttribute>(parentElement);
                if (parentCodeElement != null)
                {
                    return((EnvDTE.CodeElement)CodeAttributeArgument.Create(this.State, parentCodeElement, ordinal));
                }
            }
            else
            {
                return(parentAttributeArguments.Item(ordinal + 1)); // Needs to be 1-based to call back into code model
            }

            return(null);
        }
예제 #2
0
        protected override bool TryGetItemByIndex(int index, out EnvDTE.CodeElement element)
        {
            var node = LookupNode();

            var attributeArgumentNodes = CodeModelService.GetAttributeArgumentNodes(node);

            if (index >= 0 && index < attributeArgumentNodes.Count())
            {
                element = (EnvDTE.CodeElement)CodeAttributeArgument.Create(this.State, this.ParentAttribute, index);
                return(true);
            }

            element = null;
            return(false);
        }
예제 #3
0
        protected override bool TryGetItemByName(string name, out EnvDTE.CodeElement element)
        {
            var node         = LookupNode();
            var currentIndex = 0;

            foreach (var child in CodeModelService.GetAttributeArgumentNodes(node))
            {
                var childName = CodeModelService.GetName(child);
                if (childName == name)
                {
                    element = (EnvDTE.CodeElement)CodeAttributeArgument.Create(this.State, this.ParentAttribute, currentIndex);
                    return(true);
                }

                currentIndex++;
            }

            element = null;
            return(false);
        }