What is a Dynamic list?

Question: What is a DXCore Dynamic list?

Simple Answer: A named dictionary<string, string> with associated Name, Description and Variable.

OptionsPageTreeDynamicListsYou can locate the dynamic lists through the options screen.

It’s an advanced page, found at Core\Dynamic Lists

Note: The Dynamic lists options page is one of those pages, whose content is language based. There are lists for VB.net and C'# as well as quite a few *neutral* lists.

As stated above, each list is really a named dictionary<string, string>. 

Consider the following  list of dictionary items…

Key Value
s System.String
i System.Int32
ds System.Data.DataSet

Imagine that this list was called System Types an was associated with a variable called Type.

Now imagine another list….

Key Value
mbc MyBusinessClass
mobc MyOtherBusinessClass
mnst MyVerySpecialType

…this second list is called Custom Types and is also associated with a variable called Type.

Now let’s a imagine a CodeRush template called v?type? whose definition is…

-------------------------------------------------------------
Private «?Get(Type)» «Caret»MyVariable«BlockAnchor»;
-------------------------------------------------------------

What we have here, is a template that can be triggered by a user typing the letter v, followed by any of the items on the left side of either of the 2 lists.

Therefore the following are all valid triggers for the template:

Template Trigger Expansion
vs<space> private System.String MyVariable;
vi<space> private System.Int32 MyVariable;
vds<space> private System.Data.DataSet MyVariable;
vmbc<space> private MyBusinessClass MyVariable;
vmobc<space> private MyOtherBusinessClass MyVariable;
vmvst<space> private MyVerySpecialType MyVariable;

Note: A dynamic list can be flagged as containing .Net types. In which case it will remove any unnecessary name-spacing at expansion time, and return only the core type. This would mean returning String instead of System.String. This, I think you’ll agree, is much more aesthetic.

For those that haven’t spotted it, the example lists I mentioned for this demonstration are standard dynamic lists that already ship with CodeRush. Additonally the v?type? template is also a real template (Although the real version is a mite more complicated to allow for additional scenarios).

The first list (System Types) contains mappings for 68 of the more commonly used types in the .Net framework as well as 3 special mappings I’ll explain in a moment.
The second list (Custom Types) is initially empty when shipped but can be added to by you the user.

What about my types?UseTypeInTemplates

If you come across a business class you wish to add to this list (making it accessible by any template that uses the ?type? syntax and variable) then you can right click it and use the Use Type in Templates menu item. This will ask you what abbreviation you’d like to use for the class in question and then add it to the Custom Types list.

Special Values

The System Types list also contains 3 additional items.

Key Value
\ «?Paste»
/ «?Type»
? «?ReturnType»
 
This gives us a clue that the value n these lists, need not be entirely literal. indeed they can contain StringProviders as seen in the above examples.
 
In this case…
… v\<space> will yield a variable whose type is pasted from the clipboard.
… v/<space> will yield a variable whose type is the same as the type whose code enclosed the caret.
… v?<space> will yield a variable whose type is the same as the current method’s return type.
 
These shortcuts can obviously also save a lot of typing.

So what’s dynamic about a dynamic list

A Dynamic list is a list of mappings typically from shorter more terse strings to larger strings. The dynamic part, is that you can choose to add items to the list without informing anything that is referencing it.

This means that instead of constructing one template for each potential element in your list, you can construct a single template for the list itself, and have CodeRush do the hard work for you. Additionally if you ever choose to add to the list for any reason, you won’t have to amend the template.

Finally the same list can be reused in many many templates. (for example in CodeRush we ship v?type?, m?type?, p?type?, a?type? and r?type? )

When you add a business type to the Custom Types list, this new class is available to all those templates that make use of the Type variable with no extra work on your part.

Now that’s a big win.

In an upcoming blogpost, I’ll show you how to build some additional functionality for CodeRush using a new custom dynamic list which we’ll create for the purpose.

Free DevExpress Products - Get Your Copy Today

The following free DevExpress product offers remain available. Should you have any questions about the free offers below, please submit a ticket via the DevExpress Support Center at your convenience. We'll be happy to follow-up.
No Comments

Please login or register to post comments.