6
6
using FluentNHibernate . Automapping . TestFixtures . ComponentTypes ;
7
7
using FluentNHibernate . Automapping . TestFixtures . CustomCompositeTypes ;
8
8
using FluentNHibernate . Automapping . TestFixtures . CustomTypes ;
9
+ using FluentNHibernate . Conventions . AcceptanceCriteria ;
10
+ using FluentNHibernate . Conventions . Inspections ;
11
+ using FluentNHibernate . Conventions . Instances ;
9
12
using FluentNHibernate . Mapping ;
10
13
using FluentNHibernate . Conventions ;
11
14
using Iesi . Collections . Generic ;
@@ -135,7 +138,7 @@ public class ClassWithUserType
135
138
public class ClassWithCompositeUserType
136
139
{
137
140
public int Id { get ; set ; }
138
- public DoubleStringType DoubleStringType { get ; set ; }
141
+ public DoubleString SomeStringTuple { get ; set ; }
139
142
}
140
143
141
144
public class Customer
@@ -189,9 +192,28 @@ public class Custom
189
192
190
193
}
191
194
195
+ public class DoubleString
196
+ {
197
+ public string s1 { get ; set ; }
198
+ public string s2 { get ; set ; }
199
+ }
200
+
192
201
public class CustomTypeConvention : UserTypeConvention < CustomUserType >
193
202
{ }
194
203
204
+ public class CustomCompositeTypeConvention : IUserTypeConvention
205
+ {
206
+ public void Accept ( IAcceptanceCriteria < IPropertyInspector > criteria )
207
+ {
208
+ criteria . Expect ( x => x . Type == typeof ( DoubleString ) ) ;
209
+ }
210
+
211
+ public void Apply ( IPropertyInstance instance )
212
+ {
213
+ instance . CustomType < DoubleStringType > ( ) ;
214
+ }
215
+ }
216
+
195
217
public class CustomUserType : IUserType
196
218
{
197
219
public new bool Equals ( object x , object y )
@@ -264,28 +286,29 @@ public System.Type ReturnedClass
264
286
{
265
287
if ( x == y ) return true ;
266
288
if ( x == null || y == null ) return false ;
267
- string [ ] lhs = ( string [ ] ) x ;
268
- string [ ] rhs = ( string [ ] ) y ;
269
289
270
- return lhs [ 0 ] . Equals ( rhs [ 0 ] ) && lhs [ 1 ] . Equals ( rhs [ 1 ] ) ;
290
+ DoubleString lhs = ( DoubleString ) x ;
291
+ DoubleString rhs = ( DoubleString ) y ;
292
+
293
+ return lhs . s1 == rhs . s1 && lhs . s2 == rhs . s2 ;
271
294
}
272
295
273
296
public int GetHashCode ( object x )
274
297
{
275
298
unchecked
276
299
{
277
- string [ ] a = ( string [ ] ) x ;
278
- return a [ 0 ] . GetHashCode ( ) + 31 * a [ 1 ] . GetHashCode ( ) ;
300
+ DoubleString a = ( DoubleString ) x ;
301
+ return a . s1 . GetHashCode ( ) + 31 * a . s2 . GetHashCode ( ) ;
279
302
}
280
303
}
281
304
282
305
public Object DeepCopy ( Object x )
283
306
{
284
307
if ( x == null ) return null ;
285
- string [ ] result = new string [ 2 ] ;
286
- string [ ] input = ( string [ ] ) x ;
287
- result [ 0 ] = input [ 0 ] ;
288
- result [ 1 ] = input [ 1 ] ;
308
+ DoubleString result = new DoubleString ( ) ;
309
+ DoubleString input = ( DoubleString ) x ;
310
+ result . s1 = input . s1 ;
311
+ result . s2 = input . s2 ;
289
312
return result ;
290
313
}
291
314
@@ -305,10 +328,10 @@ public Object NullSafeGet(IDataReader rs, string[] names, ISessionImplementor se
305
328
306
329
public void NullSafeSet ( IDbCommand st , Object value , int index , ISessionImplementor session )
307
330
{
308
- string [ ] strings = ( value == null ) ? new string [ 2 ] : ( string [ ] ) value ;
331
+ DoubleString ds = value as DoubleString ?? new DoubleString ( ) ;
309
332
310
- NHibernateUtil . String . NullSafeSet ( st , strings [ 0 ] , index , session ) ;
311
- NHibernateUtil . String . NullSafeSet ( st , strings [ 1 ] , index + 1 , session ) ;
333
+ NHibernateUtil . String . NullSafeSet ( st , ds . s1 , index , session ) ;
334
+ NHibernateUtil . String . NullSafeSet ( st , ds . s2 , index + 1 , session ) ;
312
335
}
313
336
314
337
public string [ ] PropertyNames
@@ -352,103 +375,6 @@ public object Replace(object original, object target, ISessionImplementor sessio
352
375
return DeepCopy ( original ) ;
353
376
}
354
377
}
355
-
356
- /// <summary>
357
- /// Extracted from the NHibernate.Model
358
- /// </summary>
359
- public class CustomCompositeUserType : ICompositeUserType
360
- {
361
- public System . Type ReturnedClass
362
- {
363
- get { return typeof ( string [ ] ) ; }
364
- }
365
-
366
- public new bool Equals ( object x , object y )
367
- {
368
- if ( x == y ) return true ;
369
- if ( x == null || y == null ) return false ;
370
- string [ ] lhs = ( string [ ] ) x ;
371
- string [ ] rhs = ( string [ ] ) y ;
372
-
373
- return lhs [ 0 ] . Equals ( rhs [ 0 ] ) && lhs [ 1 ] . Equals ( rhs [ 1 ] ) ;
374
- }
375
-
376
- public int GetHashCode ( object x )
377
- {
378
- unchecked
379
- {
380
- string [ ] a = ( string [ ] ) x ;
381
- return a [ 0 ] . GetHashCode ( ) + 31 * a [ 1 ] . GetHashCode ( ) ;
382
- }
383
- }
384
-
385
- public Object DeepCopy ( Object x )
386
- {
387
- if ( x == null ) return null ;
388
- string [ ] result = new string [ 2 ] ;
389
- string [ ] input = ( string [ ] ) x ;
390
- result [ 0 ] = input [ 0 ] ;
391
- result [ 1 ] = input [ 1 ] ;
392
- return result ;
393
- }
394
-
395
- public bool IsMutable
396
- {
397
- get { return true ; }
398
- }
399
-
400
- public Object NullSafeGet ( IDataReader rs , string [ ] names , ISessionImplementor session , Object owner )
401
- {
402
- string first = ( string ) NHibernateUtil . String . NullSafeGet ( rs , names [ 0 ] , session , owner ) ;
403
- string second = ( string ) NHibernateUtil . String . NullSafeGet ( rs , names [ 1 ] , session , owner ) ;
404
-
405
- return ( first == null && second == null ) ? null : new string [ ] { first , second } ;
406
- }
407
-
408
- public void NullSafeSet ( IDbCommand st , Object value , int index , ISessionImplementor session )
409
- {
410
- string [ ] strings = ( value == null ) ? new string [ 2 ] : ( string [ ] ) value ;
411
-
412
- NHibernateUtil . String . NullSafeSet ( st , strings [ 0 ] , index , session ) ;
413
- NHibernateUtil . String . NullSafeSet ( st , strings [ 1 ] , index + 1 , session ) ;
414
- }
415
-
416
- public string [ ] PropertyNames
417
- {
418
- get { return new string [ ] { "s1" , "s2" } ; }
419
- }
420
-
421
- public IType [ ] PropertyTypes
422
- {
423
- get { return new IType [ ] { NHibernateUtil . String , NHibernateUtil . String } ; }
424
- }
425
-
426
- public Object GetPropertyValue ( Object component , int property )
427
- {
428
- return ( ( string [ ] ) component ) [ property ] ;
429
- }
430
-
431
- public void SetPropertyValue ( Object component , int property , Object value )
432
- {
433
- ( ( string [ ] ) component ) [ property ] = ( string ) value ;
434
- }
435
-
436
- public object Assemble ( object cached , ISessionImplementor session , object owner )
437
- {
438
- return DeepCopy ( cached ) ;
439
- }
440
-
441
- public object Disassemble ( Object value , ISessionImplementor session )
442
- {
443
- return DeepCopy ( value ) ;
444
- }
445
-
446
- public object Replace ( object original , object target , ISessionImplementor session , object owner )
447
- {
448
- return DeepCopy ( original ) ;
449
- }
450
- }
451
-
452
378
}
453
379
454
380
namespace FluentNHibernate . Automapping . TestFixtures . SuperTypes
0 commit comments