|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Collections.ObjectModel;
|
4 | 4 | using System.Linq;
|
| 5 | +using System.Reflection; |
5 | 6 | using System.Xml.Linq;
|
6 | 7 | using NHibernate.Envers.Configuration.Metadata.Reader;
|
7 | 8 | using NHibernate.Envers.Configuration.Store;
|
@@ -36,6 +37,14 @@ public sealed class CollectionMetadataGenerator
|
36 | 37 | /// </summary>
|
37 | 38 | private readonly string _referencedEntityName;
|
38 | 39 |
|
| 40 | + private static readonly MethodInfo sortedSetDefinition = ReflectHelper.GetMethodDefinition<ICollectionMapperFactory>(x => x.SortedSet<object>(null, null, null, null, false)); |
| 41 | + private static readonly MethodInfo setDefinition = ReflectHelper.GetMethodDefinition<ICollectionMapperFactory>(x => x.Set<object>(null, null, null, false)); |
| 42 | + private static readonly MethodInfo bagDefinition = ReflectHelper.GetMethodDefinition<ICollectionMapperFactory>(x => x.Bag<object>(null, null, null, false)); |
| 43 | + private static readonly MethodInfo idBagDefinition = ReflectHelper.GetMethodDefinition<ICollectionMapperFactory>(x => x.IdBag<object>(null, null, null, false)); |
| 44 | + private static readonly MethodInfo listDefinition = ReflectHelper.GetMethodDefinition<ICollectionMapperFactory>(x => x.List<object>(null, null, null, null, false)); |
| 45 | + private static readonly MethodInfo sortedMapDefinition = ReflectHelper.GetMethodDefinition<ICollectionMapperFactory>(x => x.SortedMap<object, object>(null, null, null, null, null, false)); |
| 46 | + private static readonly MethodInfo mapDefinition = ReflectHelper.GetMethodDefinition<ICollectionMapperFactory>(x => x.Map<object, object>(null, null, null, null, false)); |
| 47 | + |
39 | 48 | /// <summary>
|
40 | 49 | /// Ctor
|
41 | 50 | /// </summary>
|
@@ -502,63 +511,47 @@ private void addMapper(CommonCollectionMapperData commonCollectionMapperData, Mi
|
502 | 511 | {
|
503 | 512 | if (_propertyValue.IsSorted)
|
504 | 513 | {
|
505 |
| - var comparerType = createGenericComparerType(type); |
506 |
| - var methodInfo = ReflectHelper.GetGenericMethodFrom<ICollectionMapperFactory>("SortedSet", |
507 |
| - type.ReturnedClass.GetGenericArguments(), |
508 |
| - new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), comparerType, typeof(bool) }); |
| 514 | + var methodInfo = sortedSetDefinition.MakeGenericMethod(type.ReturnedClass.GetGenericArguments()); |
509 | 515 | collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
|
510 | 516 | new[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, _propertyValue.Comparer, embeddableElementType });
|
511 | 517 | }
|
512 | 518 | else
|
513 | 519 | {
|
514 |
| - var methodInfo = ReflectHelper.GetGenericMethodFrom<ICollectionMapperFactory>("Set", |
515 |
| - type.ReturnedClass.GetGenericArguments(), |
516 |
| - new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(bool) }); |
| 520 | + var methodInfo = setDefinition.MakeGenericMethod(type.ReturnedClass.GetGenericArguments()); |
517 | 521 | collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
|
518 | 522 | new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, embeddableElementType });
|
519 | 523 | }
|
520 | 524 | }
|
521 | 525 | else if (propertyValueType == typeof(List))
|
522 | 526 | {
|
523 |
| - var methodInfo = ReflectHelper.GetGenericMethodFrom<ICollectionMapperFactory>("List", |
524 |
| - type.ReturnedClass.GetGenericArguments(), |
525 |
| - new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(MiddleComponentData), typeof(bool) }); |
| 527 | + var methodInfo = listDefinition.MakeGenericMethod(type.ReturnedClass.GetGenericArguments()); |
526 | 528 | collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
|
527 | 529 | new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, embeddableElementType });
|
528 | 530 | }
|
529 | 531 | else if (propertyValueType == typeof (Map))
|
530 | 532 | {
|
531 | 533 | if (_propertyValue.IsSorted)
|
532 | 534 | {
|
533 |
| - var comparerType = createGenericComparerType(type); |
534 |
| - var methodInfo = ReflectHelper.GetGenericMethodFrom<ICollectionMapperFactory>("SortedMap", |
535 |
| - type.ReturnedClass.GetGenericArguments(), |
536 |
| - new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(MiddleComponentData), comparerType, typeof(bool) }); |
| 535 | + var methodInfo = sortedMapDefinition.MakeGenericMethod(type.ReturnedClass.GetGenericArguments()); |
537 | 536 | collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
|
538 | 537 | new[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, _propertyValue.Comparer, embeddableElementType });
|
539 | 538 | }
|
540 | 539 | else
|
541 | 540 | {
|
542 |
| - var methodInfo = ReflectHelper.GetGenericMethodFrom<ICollectionMapperFactory>("Map", |
543 |
| - type.ReturnedClass.GetGenericArguments(), |
544 |
| - new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(MiddleComponentData), typeof(bool) }); |
| 541 | + var methodInfo = mapDefinition.MakeGenericMethod(type.ReturnedClass.GetGenericArguments()); |
545 | 542 | collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
|
546 | 543 | new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, embeddableElementType });
|
547 | 544 | }
|
548 | 545 | }
|
549 | 546 | else if (propertyValueType == typeof(Bag))
|
550 | 547 | {
|
551 |
| - var methodInfo = ReflectHelper.GetGenericMethodFrom<ICollectionMapperFactory>("Bag", |
552 |
| - type.ReturnedClass.GetGenericArguments(), |
553 |
| - new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(bool) }); |
| 548 | + var methodInfo = bagDefinition.MakeGenericMethod(type.ReturnedClass.GetGenericArguments()); |
554 | 549 | collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
|
555 | 550 | new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, embeddableElementType });
|
556 | 551 | }
|
557 | 552 | else if (propertyValueType == typeof(IdentifierBag))
|
558 | 553 | {
|
559 |
| - var methodInfo = ReflectHelper.GetGenericMethodFrom<ICollectionMapperFactory>("IdBag", |
560 |
| - type.ReturnedClass.GetGenericArguments(), |
561 |
| - new[] { typeof(IEnversProxyFactory), typeof(CommonCollectionMapperData), typeof(MiddleComponentData), typeof(bool) }); |
| 554 | + var methodInfo = idBagDefinition.MakeGenericMethod(type.ReturnedClass.GetGenericArguments()); |
562 | 555 | collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
|
563 | 556 | new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, embeddableElementType });
|
564 | 557 | }
|
|
0 commit comments