CastConverter

this project includes classes that are used for type conversion.

These classes inherit from the abstract class CastConverter, which itself derives from TypeConverter.

public abstract class CastConverter<TFrom, TTo> : TypeConverter, ICastConverter<TFrom, TTo>
{
     …


this class contains two abstract methods:


public abstract TTo From(Object Context, TFrom value);
public abstract TFrom To(Object Context, TTo value);


the type TFrom and TTO are the types supported by the class

Inheriting CastConverter you must override these two methods to write the code for the convertion.


CastConverter contains a method to record the classes that derive from CastConverter

public static void Register<TFrom, TTo>(CastConverter<TFrom, TTo> converter)



CastConverter contains another method to automatically search all types that derive from CastConverter in an assembly.

public static void RegisterAssembly(Assembly assembly)


Types of assembly devtm.cast are already referenced in the class.

Now if you want a converter you can simply call the method Cast:

public static TTo Cast<TFrom, TTo>(Object context, TFrom value)


Remark
an exeption is thrown if no type matches.

Last edited Nov 4, 2010 at 9:36 PM by gaelgael5, version 3

Comments

No comments yet.