markrendle / Simple.Data

A light-weight, dynamic data access component for C# 4.0
MIT License
1.33k stars 303 forks source link

Support for operator conversions #310

Open seburgi opened 10 years ago

seburgi commented 10 years ago

In some of my projects I use strongly typed Ids to make my Dtos more explicit. Those Ids are mostly wrappers around a simple type (like long) with implicit conversion operators. Would be great if I could use those directly for data access with Simple.Data.

public class PersonId
{
    public PersonId(long id)
    {
        Id = id;
    }

    public PersonId() {}
    public long Id { get; protected set; }

    public static implicit operator long(PersonId id)
    {
        return id.Id;
    }

    public static implicit operator PersonId(long id)
    {
        return new PersonId(id);
    }
}