Generics Support
The ObjectDataSource does not have any kind of design time support
to use generic types and it does't support generic methods.
The CompatObjectDataSource and the ExtendedObjectDataSource
have full support for generic types and generic methods to not restrict the developer's
potential.
The syntax to specify a generic type is the same supported by the .NET Framework
GetType method.
For example, the generic type:
System.Collections.Generic`1[System.Int32]
represents the class System.Collections.Generic<int>.
For non framwork types the assembly name is also required so the syntax can be quite
complex:
Manu.GenericTests.GenericDAO`1[[Manu.Business.Product, Business]], __code
represents the class Manu.GenericTests.GenericDAO<Manu.BusinessProduct>, where
the Product class is in an assembly called Business and the GenericDAO class is
in the App_Code folder.
For generic methods, a similar syntax is available. For example:
GetObjectList`2[System.String, [Manu.GenericTests.Country, __code]]
is used to represent the GetObjectList<string, Manu.GenericTests.Country>
method.
To hide the complexity of generics, the CompatObjectDataSource
and the ExtendedObjectDataSource have full design time support,
so the developer does not need to know the underlying details.
The following example will use a generic method to get some data stored in a registry.
When the application starts a registry is created and some data is stored in it.
Among those data there is a list of available countries. The registry has the following
methods:
public class Registry
{
public T GetObject<K, T>(K
key);
public IList<T>
GetObjectList<K, T>(K key);
public void
RegisterObject<K, T>(K key, T obj);
public void
RegisterObjectList<K, T>(K key, IList<T>
objects);
}
The example use a CompatObjectDataSource to populate a DropDownList with the country
list from the registry using the GetObjectList<string, Country> method.
Country list:
|