Collection associations in Class Designer
In Beta1, Class Designer supported visualizing association relationships between two types where one type contained a field or a property whose data type is that of the second type. For example, if you had a class Customer with a property whose data type is of type “Address”, invoking the “Show as Association” command in the context menu for the property will display an association line between Customer and Address. I find this feature useful when I want to figure out how the various types in my project are associated. You will be able to visualize association regardless of whether the associated type is defined in the same VS Project or in one of its referenced assemblies.
If you had a member whose type is that of a strongly typed collection, for example, a property whose type is OrderCollection which is a collection of Orders, most of the time you will be interested in visualizing the relationship between the class and the collected type – in this case Customer and Order, rather than the class and the collection type (Customer and OrderCollection). In Beta 2, you will be able to visualize such associations. There is a new context menu “Show as Collection Association” available on field and property members that will let you visualize the relationship to the collected type.
Class Designer uses a heuristic algorithm to create the collection association line when this command is invoked. This is how it works:
For the data type of the field or property on which the command is invoked,
1) Determine if the type is a collection.
2) If it is a collection, determine the collected type.
The type is a collection if it is an array, a known generic interface (or implements one), a known non generic interface (or implements one), has an indexer or has an enumerator.
The heuristic algorithm goes something like this:
- If it is an array the collected type is the field type.
- If the type has an indexer, the indexer’s return value is the collected type.
- If the type has an enumerator, the return type of the enumerator’s Current property is the collected type.
- If the type is a known generic interface or if it implements one or a derivative of one, the generic parameter to that interface is the collected type.
- If the type is a known non- generic interface or if it implements one or a derivative of one, the collected type is Object (weak).
Let's say you have code like the following:
public class Customer
{
private IList<Order> orders;
}
If you invoke the Show as Association command on the orders field in the Customer class, you’ll see the following:
If you invoke the Show as Collection Association command on the orders field in the Customer class, you’ll get the following:
Note the two arrows in the line. That is a visual indication that this is a collection association.
Cheers,
Ramesh.
Ps: Don’t forget the web chat tonight from 5.30 P.M to 6.30 P.M PST. Here is the link to the chat room.
Comments
Anonymous
May 31, 2008
In Beta1, Class Designer supported visualizing association relationships between two types where one type contained a field or a property whose data type is that of the second type. For example, if you had a class Customer with a property whose data typAnonymous
June 06, 2008
In Beta1, Class Designer supported visualizing association relationships between two types where one type contained a field or a property whose data type is that of the second type. For example, if you had a class Customer with a property whose data typ