Skip to content

Commit 49edd8f

Browse files
committed
Removing obsolete usage of ReflectHelper.GetGenericMethodFrom
1 parent e6b893b commit 49edd8f

File tree

1 file changed

+16
-23
lines changed

1 file changed

+16
-23
lines changed

Src/NHibernate.Envers/Configuration/Metadata/CollectionMetadataGenerator.cs

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.Collections.Generic;
33
using System.Collections.ObjectModel;
44
using System.Linq;
5+
using System.Reflection;
56
using System.Xml.Linq;
67
using NHibernate.Envers.Configuration.Metadata.Reader;
78
using NHibernate.Envers.Configuration.Store;
@@ -36,6 +37,14 @@ public sealed class CollectionMetadataGenerator
3637
/// </summary>
3738
private readonly string _referencedEntityName;
3839

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+
3948
/// <summary>
4049
/// Ctor
4150
/// </summary>
@@ -502,63 +511,47 @@ private void addMapper(CommonCollectionMapperData commonCollectionMapperData, Mi
502511
{
503512
if (_propertyValue.IsSorted)
504513
{
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());
509515
collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
510516
new[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, _propertyValue.Comparer, embeddableElementType });
511517
}
512518
else
513519
{
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());
517521
collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
518522
new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, embeddableElementType });
519523
}
520524
}
521525
else if (propertyValueType == typeof(List))
522526
{
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());
526528
collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
527529
new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, embeddableElementType });
528530
}
529531
else if (propertyValueType == typeof (Map))
530532
{
531533
if (_propertyValue.IsSorted)
532534
{
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());
537536
collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
538537
new[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, _propertyValue.Comparer, embeddableElementType });
539538
}
540539
else
541540
{
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());
545542
collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
546543
new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, indexComponentData, embeddableElementType });
547544
}
548545
}
549546
else if (propertyValueType == typeof(Bag))
550547
{
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());
554549
collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
555550
new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, embeddableElementType });
556551
}
557552
else if (propertyValueType == typeof(IdentifierBag))
558553
{
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());
562555
collectionMapper = (IPropertyMapper)methodInfo.Invoke(collectionProxyMapperFactory,
563556
new object[] { _mainGenerator.GlobalCfg.EnversProxyFactory, commonCollectionMapperData, elementComponentData, embeddableElementType });
564557
}

0 commit comments

Comments
 (0)