Link Search Menu Expand Document

ClassHandler


This attribute is used to mark a class to be evaluated by the compilers during the serialization and deserialization process. By having this attribute, the library compiler (transformer) will automatically trigger the class handler Get() and Set() method for custom handling.

Implementations

Let us say you have created a customized IClassHandler like below.

private class PersonClassHandler : IClassHandler<Person>
{
    public Person Get(Person entity, DbDataReader dataReader)
    {
        EnsureConvertedProperties(entity);
        return entity;
    }

    public Person Set(Person entity)
    {
        ValidatePerson(entity);
        return entity;
    }
}

Usability

Then, you can use this attribute to mark the class to use the PersonClassHandler class handler during the transformation.

[ClassHandler(typeof(PersonClassHandler))]
public class Person
{
	public long Id { get; set; }
	public string Name { get; set; }
	public int Age { get; set; }
	public Address Address { get; set; }
	public DateTime CreatedDateUtc { get; set; }
}