using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using NHibernate; using NHibernate.SqlTypes; using NHibernate.UserTypes; namespace Sleis.Data.CustomTypes { public class NullableDecimalType : IUserType { #region IUserType Members public bool Equals(object x, object y) { return object.Equals(x, y); } public int GetHashCode(object x) { return x.GetHashCode(); } public object NullSafeGet(IDataReader rs, string[] names, object owner) { object valor = NHibernateUtil.Decimal.NullSafeGet(rs, names[0]); Decimal? inteiro = null; if (valor != null) { decimal normalized = (Decimal)valor; //possibly remove trailing 0 here. inteiro = ((Decimal)valor); } return inteiro; } public void NullSafeSet(IDbCommand cmd, object value, int index) { if (value == null) { NHibernateUtil.Decimal.NullSafeSet(cmd, null, index); } else { Decimal? inteiro = (Decimal)value; NHibernateUtil.Decimal.NullSafeSet(cmd, inteiro.Value.ToString().Replace(',', '.'), index); } } public object DeepCopy(object value) { return value; } public object Replace(object original, object target, object owner) { return original; } public object Assemble(object cached, object owner) { return cached; } public object Disassemble(object value) { return value; } public SqlType[] SqlTypes { get { return new SqlType[] { new StringSqlType() }; } } public Type ReturnedType { get { return typeof(string); } } public bool IsMutable { get { return false; } } #endregion } }