This repository has been archived by the owner on Mar 9, 2021. It is now read-only.
/
MoneyUserType.cs
58 lines (54 loc) · 1.76 KB
/
MoneyUserType.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
namespace NCommon.NHibernate.Tests.Domain
{
public class MoneyUserType : CompositeUserTypeBase<Money>
{
#region .ctor
/// <summary>
/// Default Constructor.
/// </summary>
public MoneyUserType()
{
MapProperty(prop => prop.Currency);
MapProperty(prop => prop.Amount);
}
#endregion
#region Overrides of CompositeUserTypeBase<Money>
/// <summary>
/// Inherits must build up the underlying type and return it.
/// </summary>
/// <param name="propertyValues">An array of objects that contain the values retrieved from the database.</param>
/// <returns></returns>
protected override Money CreateInstance(object[] propertyValues)
{
return new Money()
{
Currency = propertyValues[0].ToString(),
Amount = (decimal)propertyValues[1]
};
}
/// <summary>
/// Performs a deep copy of a source entity.
/// </summary>
/// <param name="source">The source entity whose deep copy should be returned.</param>
/// <returns>T</returns>
/// <remarks>
/// Inheritors must return a cloned or deep copied instance of the provided entity. If
/// </remarks>
protected override Money PerformDeepCopy(Money source)
{
return source == null ? null : new Money
{
Currency = source.Currency,
Amount = source.Amount
};
}
/// <summary>
/// Are objects of this type mutable?
/// </summary>
public override bool IsMutable
{
get { return true; }
}
#endregion
}
}