My favorites | Sign in
Project Home Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
using System;
using System.Collections.Generic;
using System.Data;
using System.Globalization;
using System.Linq;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;
using uNhAddIns.Extensions;

namespace uNhAddIns.UserTypes
{
[Serializable]
public class LocalizablePropertyType : IUserType, IParameterizedType
{
public const char DefaultKeyValueEncloser = '~';
private char keyValueEncloser = DefaultKeyValueEncloser;
protected string KeyValueEncloserParameterName = "keyValueEncloser";

private int length = 560;
protected string LengthParameterName = "length";

#region IParameterizedType Members

public void SetParameterValues(IDictionary<string, string> parameters)
{
if (parameters == null)
{
return;
}

string userSeparator;
if (parameters.TryGetValue(KeyValueEncloserParameterName, out userSeparator))
{
if (!string.IsNullOrEmpty(userSeparator))
{
keyValueEncloser = userSeparator[0];
}
}
string userLength;
if (parameters.TryGetValue(LengthParameterName, out userLength))
{
length = int.Parse(userLength);
}
}

#endregion

#region IUserType Members

public new bool Equals(object x, object y)
{
if (ReferenceEquals(null, x) && ReferenceEquals(null, y))
{
return true;
}
if (ReferenceEquals(null, x) || ReferenceEquals(null, y))
{
return false;
}
var convertedX = ((IDictionary<CultureInfo, string>)x).ToString(DefaultKeyValueEncloser);
var convertedY = ((IDictionary<CultureInfo, string>)y).ToString(DefaultKeyValueEncloser);

return convertedX.Equals(convertedY);
}

public int GetHashCode(object x)
{
if (x == null)
{
throw new ArgumentNullException("x");
}
return x.GetHashCode();
}

public object NullSafeGet(IDataReader rs, string[] names, object owner)
{
int ordinal = rs.GetOrdinal(names[0]);
if (rs.IsDBNull(ordinal))
{
return null;
}
string savedString = rs.GetString(ordinal);
if (!string.IsNullOrEmpty(savedString))
{
return savedString.SplitByEncloser(keyValueEncloser).ToPairs().ToDictionary(kv => new CultureInfo(kv.Key),
kv => kv.Value);
}
return null;
}

public void NullSafeSet(IDbCommand cmd, object value, int index)
{
if (value == null)
{
((IDbDataParameter)cmd.Parameters[index]).Value = DBNull.Value;
}
else
{
((IDbDataParameter)cmd.Parameters[index]).Value = ((IDictionary<CultureInfo, string>)value).ToString(DefaultKeyValueEncloser);
}
}

public object DeepCopy(object value)
{
return value == null ? null : new Dictionary<CultureInfo, string>((IDictionary<CultureInfo, string>)value);
}

public object Replace(object original, object target, object owner)
{
return DeepCopy(original);
}

public object Assemble(object cached, object owner)
{
return DeepCopy(cached);
}

public object Disassemble(object value)
{
return DeepCopy(value);
}

public SqlType[] SqlTypes
{
get { return new SqlType[] { SqlTypeFactory.GetString(length) }; }
}

public Type ReturnedType
{
get { return typeof(IDictionary<CultureInfo, string>); }
}

public bool IsMutable
{
get { return true; }
}

#endregion
}
}

Change log

1246ac1ac645 by Fabio Maulo <fabiomaulo> on Nov 19, 2010   Diff
Fixed LocalizablePropertyType
Go to: 
Sign in to write a code review

Older revisions

119e13249740 by Fabio Maulo <fabiomaulo> on Jun 28, 2009   Diff
Minors
c35a2ffee498 by Fabio Maulo <fabiomaulo> on Jun 28, 2009   Diff
Fix Issue-5 (LocalizablePropertyType)
All revisions of this file

File info

Size: 3394 bytes, 140 lines
Powered by Google Project Hosting