Expansions Part 2: Filtered Completion Lists

Nov 12, 2003 • 2 minutes to read

I noticed a great question from Luke Hutteman (of SharpReader fame) on Chris Sells blog. His question is:

_

“Will VS.NET also (like IDEA) be smart enough to give me a dropdown with appropriate values for the template-variables? That is, if the template calls for an IList somewhere, will it show a dropdown with all IList-type variables that are in scope at that time?"_

Note: If you’re interested in the basics of creating expansions, check out my first blog entry on expansions.

Back to Luke’s question, the answer is yes it will. In fact, the foreach expansion does exactly that by showing objects that implement the IEnumerable interface within the specific scope where the expansion was called. To do this, you can add a tag to the literal variable declaration and use the built-in function ListVariablesOfType(type)_. _Below is a fragment of the XML markup of the foreach expansion:

`

collection

Name of collection or array to iterate through

**ListVariablesOfType(System.Collections.IEnumerable)**

collection_to_loop

`

When the expansion is invoked and the user tabs to the collection variable, they will see a list of IEnumerable collections.

The code section for the foreach expansion (below) is straighforward with the collection literal being declared the same as any other variable.

`

`

PS: If you still want to code in C# but want to use IDEA tools instead of VS, this post makes it sound like we’ll soon have a version of IntelliJ for C# :)

CSharp

Generics and Anonymous Methods articles

Help shape future MSDN TV episodes