/
DoubleStringType.cs
110 lines (91 loc) · 2.52 KB
/
DoubleStringType.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Data;
using NHibernate.Engine;
using NHibernate.Type;
using NHibernate.UserTypes;
namespace NHibernate.DomainModel
{
[Serializable]
public class DoubleStringType : ICompositeUserType
{
public System.Type ReturnedClass
{
get { return typeof(string[]); }
}
public new bool Equals(object x, object y)
{
if (x == y) return true;
if (x == null || y == null) return false;
string[] lhs = (string[]) x;
string[] rhs = (string[]) y;
return lhs[0].Equals(rhs[0]) && lhs[1].Equals(rhs[1]);
}
public int GetHashCode(object x)
{
unchecked
{
string[] a = (string[]) x;
return a[0].GetHashCode() + 31 * a[1].GetHashCode();
}
}
public Object DeepCopy(Object x)
{
if (x == null) return null;
string[] result = new string[2];
string[] input = (string[]) x;
result[0] = input[0];
result[1] = input[1];
return result;
}
public bool IsMutable
{
get { return true; }
}
public Object NullSafeGet(IDataReader rs, string[] names, ISessionImplementor session, Object owner)
{
string first = (string) NHibernateUtil.String.NullSafeGet(rs, names[0], session, owner);
string second = (string) NHibernateUtil.String.NullSafeGet(rs, names[1], session, owner);
return (first == null && second == null) ? null : new string[] {first, second};
}
public void NullSafeSet(IDbCommand st, Object value, int index, bool[] settable, ISessionImplementor session)
{
string[] strings = (value == null) ? new string[2] : (string[]) value;
if (settable[0]) NHibernateUtil.String.NullSafeSet(st, strings[0], index++, session);
if (settable[1]) NHibernateUtil.String.NullSafeSet(st, strings[1], index, session);
}
public string[] PropertyNames
{
get { return new string[] {"s1", "s2"}; }
}
public IType[] PropertyTypes
{
get { return new IType[] {NHibernateUtil.String, NHibernateUtil.String}; }
}
public Object GetPropertyValue(Object component, int property)
{
return ((string[]) component)[property];
}
public void SetPropertyValue(
Object component,
int property,
Object value)
{
((string[]) component)[property] = (string) value;
}
public object Assemble(
object cached,
ISessionImplementor session,
object owner)
{
return DeepCopy(cached);
}
public object Disassemble(Object value, ISessionImplementor session)
{
return DeepCopy(value);
}
public object Replace(object original, object target, ISessionImplementor session, object owner)
{
return DeepCopy(original);
}
}
}