Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Implement EnvDTE.CodeElements.Item method.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrward committed May 26, 2012
1 parent 79307eb commit 29171ff
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Expand Up @@ -11,5 +11,7 @@ public interface CodeElements : IEnumerable
new IEnumerator GetEnumerator();

int Count { get; }

CodeElement Item(object index);
}
}
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;

using ICSharpCode.SharpDevelop.Dom;

Expand Down Expand Up @@ -71,5 +72,23 @@ public IEnumerator GetEnumerator()
{
return codeElements.GetEnumerator();
}

public CodeElement Item(object index)
{
if (index is int) {
return Item((int)index);
}
return Item((string)index);
}

CodeElement Item(int index)
{
return codeElements[index - 1];
}

CodeElement Item(string name)
{
return codeElements.Single(element => element.Name == name);
}
}
}
Expand Up @@ -110,5 +110,27 @@ public void GetEnumerator_ParentChildAndGrandChildNamespaces_ReturnsOneCodeNames

Assert.AreEqual("GrandChild", grandChildNamespace.Name);
}

[Test]
public void Item_OneClassCompletionEntryAndFirstItemSelected_ReturnsOneCodeClass()
{
helper.AddClassToProjectContent("Test", "Test.MyClass");
CreateCodeElements("Test");

CodeClass2 codeClass = codeElements.Item(1) as CodeClass2;

Assert.AreEqual("Test.MyClass", codeClass.FullName);
}

[Test]
public void Item_OneClassCompletionEntryAndItemSelectedByName_ReturnsOneCodeClass()
{
helper.AddClassToProjectContent("Test", "Test.MyClass");
CreateCodeElements("Test");

CodeClass2 codeClass = codeElements.Item("MyClass") as CodeClass2;

Assert.AreEqual("Test.MyClass", codeClass.FullName);
}
}
}

0 comments on commit 29171ff

Please sign in to comment.