Skip to content
Browse files

Implement EnvDTE.CodeElements.Item method.

  • Loading branch information...
1 parent 79307eb commit 29171ff0623fe2969cc86198109ff82a22e0cc24 @mrward mrward committed May 25, 2012
View
2 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElements.cs
@@ -11,5 +11,7 @@ public interface CodeElements : IEnumerable
new IEnumerator GetEnumerator();
int Count { get; }
+
+ CodeElement Item(object index);
}
}
View
19 src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeElementsInNamespace.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
+using System.Linq;
using ICSharpCode.SharpDevelop.Dom;
@@ -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);
+ }
}
}
View
22 src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/CodeElementsInNamespaceTests.cs
@@ -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.
Something went wrong with that request. Please try again.