New XAG Feature - Better Generics

In the original release of XAG, properties could be generic only by using aliases. That is, if you wanted to have a property with a type of "Collection<Item>" you would have to create an alias like this:

using LineItemsCollection = System.Collections.ObjectModel.Collection<XagNewGenericsExample.Item>;


private LineItemsCollection lineitems;

public LineItemsCollection LineItems {
    get { return lineitems; }
    set { lineitems = value; }

which in XAG's markup looked like this:

  <Alias x:Key="LineItemsCollection" Name="Whatever" Type="System.Collections.ObjectModel.Collection[{Type Item}]" />
  <LineItems Type="{Type LineItemsCollection}" />

That's not really a bad deal as it really helps to enforce proper type design. For example, many times I will see people doing this:

public class MyAlias : Collection<Item> {}

MyAlias is NOT an alias for Collection<Item>. Try to compare them in code, they won't match up. However, in the first example "LineItemsCollection" and "Collection<Item>" are the same.

That said, I wanted to add something a bit more flexible. So I wrote an extension markup subsystem for XAG that allows for more complex generics. Here's an example of a property using the new generics system (assuming you have the System.Collections.ObjectModel namespace in):

<LineItems Type="{GenericType Name=Collection, Types=({Type Item})}" />

As you can see it's completely inline. Now here's a more complex example:

<ComplexItems Type="{GenericType Name=Dictionary, Types=(Int32, {GenericType Name=Collection, Types=({Type Item})})}" />

This XAG property translates to the following C# property:

private Dictionary<Int32, Collection<Item>> complexitems;

public Dictionary<Int32, Collection<Item>> ComplexItems {
    get { return complexitems; }
    set { complexitems = value; }

Here's a complete example you can try on your own.

<Assembly xmlns:x="" DefaultNamespace="XagNewGenericsExample">
  <Item x:Key="Item" Type="Class" AccessModifier="Public" />
  <ItemSet x:Key="ItemSet" Type="Class" AccessModifier="Public">
      <Import Name="System.Collections.Generic" />
      <Import Name="System.Collections.ObjectModel" />
      <Items Type="{GenericType Name=Collection, Types=({Type Item})}" />
      <ComplexItems Type="{GenericType Name=Dictionary, Types=(Int32, {GenericType Name=Collection, Types=({Type Item})})}" />
So now you an have more complex generic types in your XAG structure.