diff --git a/doc/reference/modules/query_linq.xml b/doc/reference/modules/query_linq.xml index fceba0e0f39..44f413df1af 100644 --- a/doc/reference/modules/query_linq.xml +++ b/doc/reference/modules/query_linq.xml @@ -590,7 +590,7 @@ IList cats = { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(() => NullableExtensions.AsNullable(0)) + ReflectHelper.GetMethodDefinition(() => NullableExtensions.AsNullable(0)) }; } diff --git a/src/NHibernate.Test/Linq/BooleanMethodExtensionExample.cs b/src/NHibernate.Test/Linq/BooleanMethodExtensionExample.cs index 57adb33b807..08a480fc585 100644 --- a/src/NHibernate.Test/Linq/BooleanMethodExtensionExample.cs +++ b/src/NHibernate.Test/Linq/BooleanMethodExtensionExample.cs @@ -5,13 +5,12 @@ using System.Linq.Expressions; using System.Reflection; using NHibernate.Cfg; -using NHibernate.Cfg.Loquacious; using NHibernate.Hql.Ast; -using NHibernate.Linq; using NHibernate.Linq.Functions; using NHibernate.Linq.Visitors; using NHibernate.DomainModel.Northwind.Entities; using NUnit.Framework; +using NHibernate.Util; namespace NHibernate.Test.Linq { @@ -27,7 +26,7 @@ public class FreetextGenerator : BaseHqlGeneratorForMethod { public FreetextGenerator() { - SupportedMethods = new[] {ReflectionHelper.GetMethodDefinition(() => BooleanLinqExtensions.FreeText(null, null))}; + SupportedMethods = new[] {ReflectHelper.GetMethodDefinition(() => BooleanLinqExtensions.FreeText(null, null))}; } public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, @@ -48,7 +47,7 @@ public class MyLinqToHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry { public MyLinqToHqlGeneratorsRegistry() { - RegisterGenerator(ReflectionHelper.GetMethodDefinition(() => BooleanLinqExtensions.FreeText(null, null)), + RegisterGenerator(ReflectHelper.GetMethodDefinition(() => BooleanLinqExtensions.FreeText(null, null)), new FreetextGenerator()); } } diff --git a/src/NHibernate.Test/Linq/CustomExtensionsExample.cs b/src/NHibernate.Test/Linq/CustomExtensionsExample.cs index 7f65c5f359a..83336582f8d 100644 --- a/src/NHibernate.Test/Linq/CustomExtensionsExample.cs +++ b/src/NHibernate.Test/Linq/CustomExtensionsExample.cs @@ -4,12 +4,10 @@ using System.Reflection; using System.Text.RegularExpressions; using NHibernate.Cfg; -using NHibernate.Cfg.Loquacious; -using NHibernate.DomainModel.Northwind.Entities; using NHibernate.Hql.Ast; -using NHibernate.Linq; using NHibernate.Linq.Functions; using NHibernate.Linq.Visitors; +using NHibernate.Util; using NUnit.Framework; namespace NHibernate.Test.Linq @@ -30,7 +28,7 @@ public class MyLinqToHqlGeneratorsRegistry: DefaultLinqToHqlGeneratorsRegistry { public MyLinqToHqlGeneratorsRegistry():base() { - RegisterGenerator(ReflectionHelper.GetMethodDefinition(() => MyLinqExtensions.IsLike(null, null)), + RegisterGenerator(ReflectHelper.GetMethodDefinition(() => MyLinqExtensions.IsLike(null, null)), new IsLikeGenerator()); } } @@ -39,7 +37,7 @@ public class IsLikeGenerator : BaseHqlGeneratorForMethod { public IsLikeGenerator() { - SupportedMethods = new[] {ReflectionHelper.GetMethodDefinition(() => MyLinqExtensions.IsLike(null, null))}; + SupportedMethods = new[] {ReflectHelper.GetMethodDefinition(() => MyLinqExtensions.IsLike(null, null))}; } public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, diff --git a/src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/EntityWithUserTypePropertyGeneratorsRegistry.cs b/src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/EntityWithUserTypePropertyGeneratorsRegistry.cs index e8499320851..c927d9946e5 100644 --- a/src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/EntityWithUserTypePropertyGeneratorsRegistry.cs +++ b/src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/EntityWithUserTypePropertyGeneratorsRegistry.cs @@ -1,5 +1,5 @@ -using NHibernate.Linq; using NHibernate.Linq.Functions; +using NHibernate.Util; namespace NHibernate.Test.NHSpecificTest.EntityWithUserTypeCanHaveLinqGenerators { @@ -7,7 +7,7 @@ public class EntityWithUserTypePropertyGeneratorsRegistry : DefaultLinqToHqlGene { public EntityWithUserTypePropertyGeneratorsRegistry() { - RegisterGenerator(ReflectionHelper.GetMethod((IExample e) => e.IsEquivalentTo(null)), + RegisterGenerator(ReflectHelper.GetMethod((IExample e) => e.IsEquivalentTo(null)), new EntityWithUserTypePropertyIsEquivalentGenerator()); } } diff --git a/src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/EntityWithUserTypePropertyIsEquivalentGenerator.cs b/src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/EntityWithUserTypePropertyIsEquivalentGenerator.cs index eaa9676ac66..80ae4e8b34c 100644 --- a/src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/EntityWithUserTypePropertyIsEquivalentGenerator.cs +++ b/src/NHibernate.Test/NHSpecificTest/EntityWithUserTypeCanHaveLinqGenerators/EntityWithUserTypePropertyIsEquivalentGenerator.cs @@ -3,9 +3,9 @@ using System.Linq.Expressions; using System.Reflection; using NHibernate.Hql.Ast; -using NHibernate.Linq; using NHibernate.Linq.Functions; using NHibernate.Linq.Visitors; +using NHibernate.Util; namespace NHibernate.Test.NHSpecificTest.EntityWithUserTypeCanHaveLinqGenerators { @@ -13,7 +13,7 @@ public class EntityWithUserTypePropertyIsEquivalentGenerator : BaseHqlGeneratorF { public EntityWithUserTypePropertyIsEquivalentGenerator() { - SupportedMethods = new[] {ReflectionHelper.GetMethodDefinition((IExample e) => e.IsEquivalentTo(null))}; + SupportedMethods = new[] {ReflectHelper.GetMethodDefinition((IExample e) => e.IsEquivalentTo(null))}; } public override HqlTreeNode BuildHql( diff --git a/src/NHibernate.Test/NHSpecificTest/NH2318/LinqMapping.cs b/src/NHibernate.Test/NHSpecificTest/NH2318/LinqMapping.cs index f44f0b06b3e..059307e8b93 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH2318/LinqMapping.cs +++ b/src/NHibernate.Test/NHSpecificTest/NH2318/LinqMapping.cs @@ -1,14 +1,11 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; using System.Linq.Expressions; using System.Reflection; -using System.Text; using NHibernate.Hql.Ast; -using NHibernate.Linq; using NHibernate.Linq.Functions; using NHibernate.Linq.Visitors; +using NHibernate.Util; namespace NHibernate.Test.NHSpecificTest.NH2318 { @@ -31,8 +28,8 @@ public class TrimGenerator : BaseHqlGeneratorForMethod public TrimGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(() => TrimExtensions.TrimLeading(null, null)), - ReflectionHelper.GetMethodDefinition(() => TrimExtensions.TrimTrailing(null, null)), + ReflectHelper.GetMethodDefinition(() => TrimExtensions.TrimLeading(null, null)), + ReflectHelper.GetMethodDefinition(() => TrimExtensions.TrimTrailing(null, null)), }; } diff --git a/src/NHibernate.Test/NHSpecificTest/NH2869/IsTrueInDbFalseInLocalGenerator.cs b/src/NHibernate.Test/NHSpecificTest/NH2869/IsTrueInDbFalseInLocalGenerator.cs index 8b1eb31b85a..a685b2e61d0 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH2869/IsTrueInDbFalseInLocalGenerator.cs +++ b/src/NHibernate.Test/NHSpecificTest/NH2869/IsTrueInDbFalseInLocalGenerator.cs @@ -2,9 +2,9 @@ using System.Linq.Expressions; using System.Reflection; using NHibernate.Hql.Ast; -using NHibernate.Linq; using NHibernate.Linq.Functions; using NHibernate.Linq.Visitors; +using NHibernate.Util; namespace NHibernate.Test.NHSpecificTest.NH2869 { @@ -12,7 +12,7 @@ public class IsTrueInDbFalseInLocalGenerator : BaseHqlGeneratorForMethod { public IsTrueInDbFalseInLocalGenerator() { - SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition(() => MyLinqExtensions.IsOneInDbZeroInLocal(null, null)) }; + SupportedMethods = new[] { ReflectHelper.GetMethodDefinition(() => MyLinqExtensions.IsOneInDbZeroInLocal(null, null)) }; } public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) diff --git a/src/NHibernate.Test/NHSpecificTest/NH2869/MyLinqToHqlGeneratorsRegistry.cs b/src/NHibernate.Test/NHSpecificTest/NH2869/MyLinqToHqlGeneratorsRegistry.cs index 95b1591985f..cb8869c3cfe 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH2869/MyLinqToHqlGeneratorsRegistry.cs +++ b/src/NHibernate.Test/NHSpecificTest/NH2869/MyLinqToHqlGeneratorsRegistry.cs @@ -1,5 +1,5 @@ -using NHibernate.Linq; using NHibernate.Linq.Functions; +using NHibernate.Util; namespace NHibernate.Test.NHSpecificTest.NH2869 { @@ -7,7 +7,7 @@ public class MyLinqToHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry { public MyLinqToHqlGeneratorsRegistry() { - RegisterGenerator(ReflectionHelper.GetMethodDefinition(() => MyLinqExtensions.IsOneInDbZeroInLocal(null, null)), new IsTrueInDbFalseInLocalGenerator()); + RegisterGenerator(ReflectHelper.GetMethodDefinition(() => MyLinqExtensions.IsOneInDbZeroInLocal(null, null)), new IsTrueInDbFalseInLocalGenerator()); } } } \ No newline at end of file diff --git a/src/NHibernate.Test/NHSpecificTest/NH3604/FixtureByCode.cs b/src/NHibernate.Test/NHSpecificTest/NH3604/FixtureByCode.cs index f4ced8adc6e..02cde1676c8 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH3604/FixtureByCode.cs +++ b/src/NHibernate.Test/NHSpecificTest/NH3604/FixtureByCode.cs @@ -2,6 +2,7 @@ using NHibernate.Cfg.MappingSchema; using NHibernate.Linq; using NHibernate.Mapping.ByCode; +using NHibernate.Util; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest.NH3604 @@ -23,7 +24,7 @@ protected override HbmMapping GetMappings() mapper.Class(rc => { - rc.Id(x => x.Id, m => m.Generator(new ForeignGeneratorDef(ReflectionHelper.GetProperty(EntityDetail.PropertyAccessExpressions.Entity)))); + rc.Id(x => x.Id, m => m.Generator(new ForeignGeneratorDef(ReflectHelper.GetProperty(EntityDetail.PropertyAccessExpressions.Entity)))); rc.OneToOne(EntityDetail.PropertyAccessExpressions.Entity, m => m.Constrained(true)); rc.Property(x => x.ExtraInfo); }); diff --git a/src/NHibernate.Test/NHSpecificTest/NH3952/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/NH3952/Fixture.cs index dea02b22cd0..200e338cd15 100644 --- a/src/NHibernate.Test/NHSpecificTest/NH3952/Fixture.cs +++ b/src/NHibernate.Test/NHSpecificTest/NH3952/Fixture.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Reflection; using NHibernate.Linq; +using NHibernate.Util; using NUnit.Framework; namespace NHibernate.Test.NHSpecificTest.NH3952 @@ -83,10 +84,10 @@ public void ArraySelect() } } - private static readonly MethodInfo CastMethodDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo CastMethodDefinition = ReflectHelper.GetMethodDefinition( () => Enumerable.Cast(null)); - private static readonly MethodInfo CastMethod = ReflectionHelper.GetMethod( + private static readonly MethodInfo CastMethod = ReflectHelper.GetMethod( () => Enumerable.Cast(null)); [Test, Explicit("Just a blunt perf comparison among some reflection patterns used in NH")] @@ -132,7 +133,7 @@ public void ReflectionBluntPerfCompare() swRefl.Start(); for (var i = 0; i < 1000; i++) { - var cast = ReflectionHelper.GetMethod(() => Enumerable.Cast(null)); + var cast = ReflectHelper.GetMethod(() => Enumerable.Cast(null)); Trace.TraceInformation(cast.ToString()); } swRefl.Stop(); @@ -141,7 +142,7 @@ public void ReflectionBluntPerfCompare() swReflDef.Start(); for (var i = 0; i < 1000; i++) { - var cast = ReflectionHelper.GetMethodDefinition(() => Enumerable.Cast(null)) + var cast = ReflectHelper.GetMethodDefinition(() => Enumerable.Cast(null)) .MakeGenericMethod(new[] { typeof(int) }); Trace.TraceInformation(cast.ToString()); } @@ -164,8 +165,8 @@ public void ReflectionBluntPerfCompare() Cached method definition + make gen: {1} Hazzik GetMethod: {5} Hazzik GetMethodDefinition + make gen: {6} -ReflectionHelper.GetMethod: {2} -ReflectionHelper.GetMethodDefinition + make gen: {3} +ReflectHelper.GetMethod: {2} +ReflectHelper.GetMethodDefinition + make gen: {3} EnumerableHelper.GetMethod(generic overload): {4}", swCached.Elapsed, swCachedDef.Elapsed, swRefl.Elapsed, swReflDef.Elapsed, swEnHlp.Elapsed, swRefl2.Elapsed, swRefl2Def.Elapsed); diff --git a/src/NHibernate.Test/UtilityTest/ReflectionHelperIsMethodOfTests.cs b/src/NHibernate.Test/UtilityTest/ReflectionHelperIsMethodOfTests.cs index c9becea4f56..0037208fcdb 100644 --- a/src/NHibernate.Test/UtilityTest/ReflectionHelperIsMethodOfTests.cs +++ b/src/NHibernate.Test/UtilityTest/ReflectionHelperIsMethodOfTests.cs @@ -18,14 +18,14 @@ public void WhenNullMethodInfoThenThrows() [Test] public void WhenNullTypeThenThrows() { - var methodInfo = ReflectionHelper.GetMethodDefinition>(t => t.Contains(5)); + var methodInfo = ReflectHelper.GetMethodDefinition>(t => t.Contains(5)); Assert.Throws(() => methodInfo.IsMethodOf(null)); } [Test] public void WhenDeclaringTypeMatchThenTrue() { - Assert.That(ReflectionHelper.GetMethodDefinition>(t => t.Contains(5)).IsMethodOf(typeof(List)), Is.True); + Assert.That(ReflectHelper.GetMethodDefinition>(t => t.Contains(5)).IsMethodOf(typeof(List)), Is.True); } private class MyCollection: List @@ -36,33 +36,33 @@ private class MyCollection: List [Test] public void WhenCustomTypeMatchThenTrue() { - Assert.That(ReflectionHelper.GetMethodDefinition(t => t.Contains(5)).IsMethodOf(typeof(List)), Is.True); + Assert.That(ReflectHelper.GetMethodDefinition(t => t.Contains(5)).IsMethodOf(typeof(List)), Is.True); } [Test] public void WhenTypeIsGenericDefinitionAndMatchThenTrue() { - Assert.That(ReflectionHelper.GetMethodDefinition>(t => t.Contains(5)).IsMethodOf(typeof(List<>)), Is.True); + Assert.That(ReflectHelper.GetMethodDefinition>(t => t.Contains(5)).IsMethodOf(typeof(List<>)), Is.True); } [Test] public void WhenTypeIsGenericImplementedInterfaceAndMatchThenTrue() { - var containsMethodDefinition = ReflectionHelper.GetMethodDefinition>(t => t.Contains(5)); + var containsMethodDefinition = ReflectHelper.GetMethodDefinition>(t => t.Contains(5)); Assert.That(containsMethodDefinition.IsMethodOf(typeof(ICollection)), Is.True); } [Test] public void WhenTypeIsGenericImplementedInterfaceAndMatchGenericInterfaceDefinitionThenTrue() { - var containsMethodDefinition = ReflectionHelper.GetMethodDefinition>(t => t.Contains(5)); + var containsMethodDefinition = ReflectHelper.GetMethodDefinition>(t => t.Contains(5)); Assert.That(containsMethodDefinition.IsMethodOf(typeof(ICollection<>)), Is.True); } [Test] public void WhenNoMatchThenFalse() { - Assert.That(ReflectionHelper.GetMethodDefinition>(t => t.Contains(5)).IsMethodOf(typeof(IEnumerable<>)), Is.False); + Assert.That(ReflectHelper.GetMethodDefinition>(t => t.Contains(5)).IsMethodOf(typeof(IEnumerable<>)), Is.False); } private abstract class MyAbstractClass @@ -78,14 +78,14 @@ private class MyClass : MyAbstractClass [Test] public void WhenTypeIsGenericImplementedAbstractAndMatchThenTrue() { - var containsMethodDefinition = ReflectionHelper.GetMethodDefinition(t => t.MyMethod()); + var containsMethodDefinition = ReflectHelper.GetMethodDefinition(t => t.MyMethod()); Assert.That(containsMethodDefinition.IsMethodOf(typeof(MyAbstractClass)), Is.True); } [Test] public void WhenTypeIsGenericImplementedAbstractAndMatchGenericInterfaceDefinitionThenTrue() { - var containsMethodDefinition = ReflectionHelper.GetMethodDefinition(t => t.MyMethod()); + var containsMethodDefinition = ReflectHelper.GetMethodDefinition(t => t.MyMethod()); Assert.That(containsMethodDefinition.IsMethodOf(typeof(MyAbstractClass<>)), Is.True); } } diff --git a/src/NHibernate.Test/UtilityTest/ReflectionHelperTest.cs b/src/NHibernate.Test/UtilityTest/ReflectionHelperTest.cs index 857b762ba71..ad74afd4394 100644 --- a/src/NHibernate.Test/UtilityTest/ReflectionHelperTest.cs +++ b/src/NHibernate.Test/UtilityTest/ReflectionHelperTest.cs @@ -1,7 +1,7 @@ using System; using System.Linq; using System.Linq.Expressions; -using NHibernate.Linq; +using NHibernate.Util; using NUnit.Framework; namespace NHibernate.Test.UtilityTest @@ -19,55 +19,55 @@ public void GenericMethod() { } [Test] public void WhenGetMethodForNullThenThrows() { - Assert.That(() => ReflectionHelper.GetMethodDefinition((Expression) null), Throws.TypeOf()); + Assert.That(() => ReflectHelper.GetMethodDefinition((Expression) null), Throws.TypeOf()); } [Test] public void WhenGenericGetMethodForNullThenThrows() { - Assert.That(() => ReflectionHelper.GetMethodDefinition((Expression>)null), Throws.TypeOf()); + Assert.That(() => ReflectHelper.GetMethodDefinition((Expression>)null), Throws.TypeOf()); } [Test] public void WhenGetPropertyForNullThenThrows() { - Assert.That(() => ReflectionHelper.GetProperty(null), Throws.TypeOf()); + Assert.That(() => ReflectHelper.GetProperty(null), Throws.TypeOf()); } [Test] public void WhenGenericMethodOfClassThenReturnGenericDefinition() { - Assert.That(ReflectionHelper.GetMethodDefinition(mc => mc.GenericMethod()), Is.EqualTo(typeof (MyClass).GetMethod("GenericMethod").GetGenericMethodDefinition())); + Assert.That(ReflectHelper.GetMethodDefinition(mc => mc.GenericMethod()), Is.EqualTo(typeof (MyClass).GetMethod("GenericMethod").GetGenericMethodDefinition())); } [Test] public void WhenNoGenericMethodOfClassThenReturnDefinition() { - Assert.That(ReflectionHelper.GetMethodDefinition(mc => mc.NoGenericMethod()), Is.EqualTo(typeof(MyClass).GetMethod("NoGenericMethod"))); + Assert.That(ReflectHelper.GetMethodDefinition(mc => mc.NoGenericMethod()), Is.EqualTo(typeof(MyClass).GetMethod("NoGenericMethod"))); } [Test] public void WhenStaticGenericMethodThenReturnGenericDefinition() { - Assert.That(ReflectionHelper.GetMethodDefinition(() => Enumerable.All(null, null)), Is.EqualTo(typeof(Enumerable).GetMethod("All").GetGenericMethodDefinition())); + Assert.That(ReflectHelper.GetMethodDefinition(() => Enumerable.All(null, null)), Is.EqualTo(typeof(Enumerable).GetMethod("All").GetGenericMethodDefinition())); } [Test] public void WhenStaticNoGenericMethodThenReturnDefinition() { - Assert.That(ReflectionHelper.GetMethodDefinition(() => string.Join(null, null)), Is.EqualTo(typeof(string).GetMethod("Join", new []{typeof(string), typeof(string[])}))); + Assert.That(ReflectHelper.GetMethodDefinition(() => string.Join(null, null)), Is.EqualTo(typeof(string).GetMethod("Join", new []{typeof(string), typeof(string[])}))); } [Test] public void WhenGetPropertyThenReturnPropertyInfo() { - Assert.That(ReflectionHelper.GetProperty(mc => mc.BaseProperty), Is.EqualTo(typeof(MyClass).GetProperty("BaseProperty"))); + Assert.That(ReflectHelper.GetProperty(mc => mc.BaseProperty), Is.EqualTo(typeof(MyClass).GetProperty("BaseProperty"))); } [Test] public void WhenGetPropertyForBoolThenReturnPropertyInfo() { - Assert.That(ReflectionHelper.GetProperty(mc => mc.BaseBool), Is.EqualTo(typeof(MyClass).GetProperty("BaseBool"))); + Assert.That(ReflectHelper.GetProperty(mc => mc.BaseBool), Is.EqualTo(typeof(MyClass).GetProperty("BaseBool"))); } } } \ No newline at end of file diff --git a/src/NHibernate/Bytecode/EmitUtil.cs b/src/NHibernate/Bytecode/EmitUtil.cs index ff615ef90c2..a6ba3b1fb6c 100644 --- a/src/NHibernate/Bytecode/EmitUtil.cs +++ b/src/NHibernate/Bytecode/EmitUtil.cs @@ -197,7 +197,7 @@ public static void EmitLoadMethodInfo(ILGenerator il, MethodInfo methodInfo) il.Emit(OpCodes.Castclass, typeof(MethodInfo)); } - private static readonly MethodInfo CreateDelegate = ReflectionHelper.GetMethod( + private static readonly MethodInfo CreateDelegate = ReflectHelper.GetMethod( () => Delegate.CreateDelegate(null, null)); public static void EmitCreateDelegateInstance(ILGenerator il, System.Type delegateType, MethodInfo methodInfo) diff --git a/src/NHibernate/Bytecode/Lightweight/ReflectionOptimizer.cs b/src/NHibernate/Bytecode/Lightweight/ReflectionOptimizer.cs index 64c5d88a760..7bdff38d8da 100644 --- a/src/NHibernate/Bytecode/Lightweight/ReflectionOptimizer.cs +++ b/src/NHibernate/Bytecode/Lightweight/ReflectionOptimizer.cs @@ -119,7 +119,7 @@ private static void EmitCastToReference(ILGenerator il, System.Type type) } } - private static readonly MethodInfo GetterCallbackInvoke = ReflectionHelper.GetMethod( + private static readonly MethodInfo GetterCallbackInvoke = ReflectHelper.GetMethod( g => g.Invoke(null, 0)); /// @@ -185,7 +185,7 @@ private GetPropertyValuesInvoker GenerateGetPropertyValuesMethod(IGetter[] gette return (GetPropertyValuesInvoker) method.CreateDelegate(typeof (GetPropertyValuesInvoker)); } - private static readonly MethodInfo SetterCallbackInvoke = ReflectionHelper.GetMethod( + private static readonly MethodInfo SetterCallbackInvoke = ReflectHelper.GetMethod( g => g.Invoke(null, 0, null)); /// diff --git a/src/NHibernate/Linq/DefaultQueryProvider.cs b/src/NHibernate/Linq/DefaultQueryProvider.cs index 6ca8dc25846..e2c9d09f441 100644 --- a/src/NHibernate/Linq/DefaultQueryProvider.cs +++ b/src/NHibernate/Linq/DefaultQueryProvider.cs @@ -7,6 +7,7 @@ using NHibernate.Engine; using NHibernate.Impl; using NHibernate.Type; +using NHibernate.Util; namespace NHibernate.Linq { @@ -18,7 +19,7 @@ public interface INhQueryProvider : IQueryProvider public class DefaultQueryProvider : INhQueryProvider { - private static readonly MethodInfo CreateQueryMethodDefinition = ReflectionHelper.GetMethodDefinition((INhQueryProvider p) => p.CreateQuery(null)); + private static readonly MethodInfo CreateQueryMethodDefinition = ReflectHelper.GetMethodDefinition((INhQueryProvider p) => p.CreateQuery(null)); private readonly WeakReference _session; @@ -79,8 +80,8 @@ protected virtual NhLinqExpression PrepareQuery(Expression expression, out IQuer return nhLinqExpression; } - private static readonly MethodInfo Future = ReflectionHelper.GetMethodDefinition(q => q.Future()); - private static readonly MethodInfo FutureValue = ReflectionHelper.GetMethodDefinition(q => q.FutureValue()); + private static readonly MethodInfo Future = ReflectHelper.GetMethodDefinition(q => q.Future()); + private static readonly MethodInfo FutureValue = ReflectHelper.GetMethodDefinition(q => q.FutureValue()); protected virtual object ExecuteFutureQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery) { diff --git a/src/NHibernate/Linq/EnumerableHelper.cs b/src/NHibernate/Linq/EnumerableHelper.cs index f36bf432506..835c2ab4a4c 100644 --- a/src/NHibernate/Linq/EnumerableHelper.cs +++ b/src/NHibernate/Linq/EnumerableHelper.cs @@ -2,9 +2,11 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using NHibernate.Util; namespace NHibernate.Linq { + [Obsolete("Please use NHibernate.Util.ReflectHelper instead")] public static class ReflectionHelper { /// @@ -16,8 +18,7 @@ public static class ReflectionHelper /// public static MethodInfo GetMethodDefinition(Expression> method) { - MethodInfo methodInfo = GetMethod(method); - return methodInfo.IsGenericMethod ? methodInfo.GetGenericMethodDefinition() : methodInfo; + return ReflectHelper.GetMethodDefinition(method); } /// @@ -28,10 +29,7 @@ public static MethodInfo GetMethodDefinition(Expression /// The of the method. public static MethodInfo GetMethod(Expression> method) { - if (method == null) - throw new ArgumentNullException("method"); - - return ((MethodCallExpression)method.Body).Method; + return ReflectHelper.GetMethod(method); } /// @@ -42,8 +40,7 @@ public static MethodInfo GetMethod(Expression> method) /// public static MethodInfo GetMethodDefinition(Expression method) { - MethodInfo methodInfo = GetMethod(method); - return methodInfo.IsGenericMethod ? methodInfo.GetGenericMethodDefinition() : methodInfo; + return ReflectHelper.GetMethodDefinition(method); } /// @@ -53,10 +50,7 @@ public static MethodInfo GetMethodDefinition(Expression method) /// The of the method. public static MethodInfo GetMethod(Expression method) { - if (method == null) - throw new ArgumentNullException("method"); - - return ((MethodCallExpression)method.Body).Method; + return ReflectHelper.GetMethod(method); } /// @@ -68,32 +62,11 @@ public static MethodInfo GetMethod(Expression method) /// The of the property. public static MemberInfo GetProperty(Expression> property) { - if (property == null) - { - throw new ArgumentNullException("property"); - } - return ((MemberExpression)property.Body).Member; - } - - internal static System.Type GetPropertyOrFieldType(this MemberInfo memberInfo) - { - var propertyInfo = memberInfo as PropertyInfo; - if (propertyInfo != null) - { - return propertyInfo.PropertyType; - } - - var fieldInfo = memberInfo as FieldInfo; - if (fieldInfo != null) - { - return fieldInfo.FieldType; - } - - return null; + return ReflectHelper.GetProperty(property); } } - [Obsolete("Please use ReflectionHelper instead")] + [Obsolete("Please use NHibernate.Util.ReflectHelper instead")] public static class EnumerableHelper { public static MethodInfo GetMethod(string name, System.Type[] parameterTypes) diff --git a/src/NHibernate/Linq/ExpressionTransformers/SimplifyCompareTransformer.cs b/src/NHibernate/Linq/ExpressionTransformers/SimplifyCompareTransformer.cs index 28a5183e373..73ee8d974f6 100644 --- a/src/NHibernate/Linq/ExpressionTransformers/SimplifyCompareTransformer.cs +++ b/src/NHibernate/Linq/ExpressionTransformers/SimplifyCompareTransformer.cs @@ -4,6 +4,7 @@ using System.Linq.Expressions; using System.Reflection; using NHibernate.Linq.Functions; +using NHibernate.Util; using Remotion.Linq.Parsing.ExpressionTreeVisitors.Transformation; namespace NHibernate.Linq.ExpressionTransformers @@ -105,13 +106,13 @@ private Expression Build(ExpressionType et, Expression expression) private static readonly IDictionary dummies = new Dictionary { // Corresponds to string.Compare(a, b). - {typeof (string), ReflectionHelper.GetMethod(() => DummyComparison(null, null))}, + {typeof (string), ReflectHelper.GetMethod(() => DummyComparison(null, null))}, // System.Data.Services.Providers.DataServiceProviderMethods has Compare methods for these types. - {typeof (bool), ReflectionHelper.GetMethod(() => DummyComparison(false, false))}, - {typeof (bool?), ReflectionHelper.GetMethod(() => DummyComparison(null, null))}, - {typeof (Guid), ReflectionHelper.GetMethod(() => DummyComparison(Guid.Empty, Guid.Empty))}, - {typeof (Guid?), ReflectionHelper.GetMethod(() => DummyComparison(null, null))}, + {typeof (bool), ReflectHelper.GetMethod(() => DummyComparison(false, false))}, + {typeof (bool?), ReflectHelper.GetMethod(() => DummyComparison(null, null))}, + {typeof (Guid), ReflectHelper.GetMethod(() => DummyComparison(Guid.Empty, Guid.Empty))}, + {typeof (Guid?), ReflectHelper.GetMethod(() => DummyComparison(null, null))}, }; diff --git a/src/NHibernate/Linq/Functions/CompareGenerator.cs b/src/NHibernate/Linq/Functions/CompareGenerator.cs index 870d8330cba..591fb28d3cb 100644 --- a/src/NHibernate/Linq/Functions/CompareGenerator.cs +++ b/src/NHibernate/Linq/Functions/CompareGenerator.cs @@ -6,6 +6,7 @@ using NHibernate.Hql.Ast; using NHibernate.Linq.Visitors; using System.Linq; +using NHibernate.Util; namespace NHibernate.Linq.Functions { @@ -13,28 +14,28 @@ internal class CompareGenerator : BaseHqlGeneratorForMethod, IRuntimeMethodHqlGe { private static readonly HashSet ActingMethods = new HashSet { - ReflectionHelper.GetMethodDefinition(() => string.Compare(null, null)), - ReflectionHelper.GetMethodDefinition(s => s.CompareTo(s)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(() => string.Compare(null, null)), + ReflectHelper.GetMethodDefinition(s => s.CompareTo(s)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), - ReflectionHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), + ReflectHelper.GetMethodDefinition(x => x.CompareTo(x)), }; internal static bool IsCompareMethod(MethodInfo methodInfo) diff --git a/src/NHibernate/Linq/Functions/ConvertGenerator.cs b/src/NHibernate/Linq/Functions/ConvertGenerator.cs index c9e8e501f98..2b1812048e0 100644 --- a/src/NHibernate/Linq/Functions/ConvertGenerator.cs +++ b/src/NHibernate/Linq/Functions/ConvertGenerator.cs @@ -3,10 +3,10 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; -using System.Text; using NHibernate.Hql.Ast; using NHibernate.Linq.Visitors; using System.Collections.ObjectModel; +using NHibernate.Util; namespace NHibernate.Linq.Functions { @@ -24,10 +24,10 @@ public class ConvertToDateTimeGenerator : ConvertToGenerator public ConvertToDateTimeGenerator() { SupportedMethods = new[] - { - ReflectionHelper.GetMethodDefinition(s => DateTime.Parse(s)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDateTime(o)) - }; + { + ReflectHelper.GetMethodDefinition(s => DateTime.Parse(s)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDateTime(o)) + }; } } @@ -37,10 +37,10 @@ public class ConvertToBooleanGenerator : ConvertToGenerator public ConvertToBooleanGenerator() { SupportedMethods = new[] - { - ReflectionHelper.GetMethodDefinition(s => Boolean.Parse(s)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToBoolean(o)) - }; + { + ReflectHelper.GetMethodDefinition(s => Boolean.Parse(s)), + ReflectHelper.GetMethodDefinition(o => Convert.ToBoolean(o)) + }; } } @@ -51,22 +51,22 @@ public ConvertToInt32Generator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(s => int.Parse(s)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToInt32(o)) + ReflectHelper.GetMethodDefinition(s => int.Parse(s)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToInt32(o)) }; } } @@ -77,21 +77,21 @@ public ConvertToDecimalGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(s => decimal.Parse(s)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDecimal(o)) + ReflectHelper.GetMethodDefinition(s => decimal.Parse(s)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDecimal(o)) }; } } @@ -102,21 +102,21 @@ public ConvertToDoubleGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(s => double.Parse(s)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)), - ReflectionHelper.GetMethodDefinition(o => Convert.ToDouble(o)) + ReflectHelper.GetMethodDefinition(s => double.Parse(s)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)), + ReflectHelper.GetMethodDefinition(o => Convert.ToDouble(o)) }; } } diff --git a/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs b/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs index 4ffcd0f9f50..a8b26787f47 100644 --- a/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs +++ b/src/NHibernate/Linq/Functions/DateTimePropertiesHqlGenerator.cs @@ -1,9 +1,9 @@ using System; -using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; using NHibernate.Hql.Ast; using NHibernate.Linq.Visitors; +using NHibernate.Util; namespace NHibernate.Linq.Functions { @@ -13,21 +13,21 @@ public DateTimePropertiesHqlGenerator() { SupportedProperties = new[] { - ReflectionHelper.GetProperty((DateTime x) => x.Year), - ReflectionHelper.GetProperty((DateTime x) => x.Month), - ReflectionHelper.GetProperty((DateTime x) => x.Day), - ReflectionHelper.GetProperty((DateTime x) => x.Hour), - ReflectionHelper.GetProperty((DateTime x) => x.Minute), - ReflectionHelper.GetProperty((DateTime x) => x.Second), - ReflectionHelper.GetProperty((DateTime x) => x.Date), + ReflectHelper.GetProperty((DateTime x) => x.Year), + ReflectHelper.GetProperty((DateTime x) => x.Month), + ReflectHelper.GetProperty((DateTime x) => x.Day), + ReflectHelper.GetProperty((DateTime x) => x.Hour), + ReflectHelper.GetProperty((DateTime x) => x.Minute), + ReflectHelper.GetProperty((DateTime x) => x.Second), + ReflectHelper.GetProperty((DateTime x) => x.Date), - ReflectionHelper.GetProperty((DateTimeOffset x) => x.Year), - ReflectionHelper.GetProperty((DateTimeOffset x) => x.Month), - ReflectionHelper.GetProperty((DateTimeOffset x) => x.Day), - ReflectionHelper.GetProperty((DateTimeOffset x) => x.Hour), - ReflectionHelper.GetProperty((DateTimeOffset x) => x.Minute), - ReflectionHelper.GetProperty((DateTimeOffset x) => x.Second), - ReflectionHelper.GetProperty((DateTimeOffset x) => x.Date), + ReflectHelper.GetProperty((DateTimeOffset x) => x.Year), + ReflectHelper.GetProperty((DateTimeOffset x) => x.Month), + ReflectHelper.GetProperty((DateTimeOffset x) => x.Day), + ReflectHelper.GetProperty((DateTimeOffset x) => x.Hour), + ReflectHelper.GetProperty((DateTimeOffset x) => x.Minute), + ReflectHelper.GetProperty((DateTimeOffset x) => x.Second), + ReflectHelper.GetProperty((DateTimeOffset x) => x.Date), }; } diff --git a/src/NHibernate/Linq/Functions/EqualsGenerator.cs b/src/NHibernate/Linq/Functions/EqualsGenerator.cs index 06d19e011bc..a7c8b52102c 100644 --- a/src/NHibernate/Linq/Functions/EqualsGenerator.cs +++ b/src/NHibernate/Linq/Functions/EqualsGenerator.cs @@ -1,10 +1,10 @@ using System; using System.Collections.ObjectModel; -using System.Linq; using System.Linq.Expressions; using System.Reflection; using NHibernate.Hql.Ast; using NHibernate.Linq.Visitors; +using NHibernate.Util; namespace NHibernate.Linq.Functions { @@ -14,30 +14,30 @@ public EqualsGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(() => string.Equals(default(string), default(string))), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(() => string.Equals(default(string), default(string))), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(x)), - ReflectionHelper.GetMethodDefinition(x => x.Equals(default(bool))) + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(x)), + ReflectHelper.GetMethodDefinition(x => x.Equals(default(bool))) }; } diff --git a/src/NHibernate/Linq/Functions/MathGenerator.cs b/src/NHibernate/Linq/Functions/MathGenerator.cs index 5215ce2f7f9..aff4807f73b 100644 --- a/src/NHibernate/Linq/Functions/MathGenerator.cs +++ b/src/NHibernate/Linq/Functions/MathGenerator.cs @@ -4,6 +4,7 @@ using System.Reflection; using NHibernate.Hql.Ast; using NHibernate.Linq.Visitors; +using NHibernate.Util; namespace NHibernate.Linq.Functions { @@ -12,51 +13,51 @@ public class MathGenerator : BaseHqlGeneratorForMethod public MathGenerator() { SupportedMethods = new[] - { - ReflectionHelper.GetMethodDefinition(() => Math.Sin(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Cos(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Tan(default(double))), - - ReflectionHelper.GetMethodDefinition(() => Math.Sinh(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Cosh(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Tanh(default(double))), - - ReflectionHelper.GetMethodDefinition(() => Math.Asin(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Acos(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Atan(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Atan2(default(double), default(double))), + { + ReflectHelper.GetMethodDefinition(() => Math.Sin(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Cos(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Tan(default(double))), + + ReflectHelper.GetMethodDefinition(() => Math.Sinh(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Cosh(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Tanh(default(double))), + + ReflectHelper.GetMethodDefinition(() => Math.Asin(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Acos(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Atan(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Atan2(default(double), default(double))), + + ReflectHelper.GetMethodDefinition(() => Math.Sqrt(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Sqrt(default(double))), - - ReflectionHelper.GetMethodDefinition(() => Math.Abs(default(decimal))), - ReflectionHelper.GetMethodDefinition(() => Math.Abs(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Abs(default(float))), - ReflectionHelper.GetMethodDefinition(() => Math.Abs(default(long))), - ReflectionHelper.GetMethodDefinition(() => Math.Abs(default(int))), - ReflectionHelper.GetMethodDefinition(() => Math.Abs(default(short))), - ReflectionHelper.GetMethodDefinition(() => Math.Abs(default(sbyte))), - - ReflectionHelper.GetMethodDefinition(() => Math.Sign(default(decimal))), - ReflectionHelper.GetMethodDefinition(() => Math.Sign(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Sign(default(float))), - ReflectionHelper.GetMethodDefinition(() => Math.Sign(default(long))), - ReflectionHelper.GetMethodDefinition(() => Math.Sign(default(int))), - ReflectionHelper.GetMethodDefinition(() => Math.Sign(default(short))), - ReflectionHelper.GetMethodDefinition(() => Math.Sign(default(sbyte))), - - ReflectionHelper.GetMethodDefinition(() => Math.Round(default(decimal))), - ReflectionHelper.GetMethodDefinition(() => Math.Round(default(decimal), default(int))), - ReflectionHelper.GetMethodDefinition(() => Math.Round(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Round(default(double), default(int))), - ReflectionHelper.GetMethodDefinition(() => Math.Floor(default(decimal))), - ReflectionHelper.GetMethodDefinition(() => Math.Floor(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Ceiling(default(decimal))), - ReflectionHelper.GetMethodDefinition(() => Math.Ceiling(default(double))), - ReflectionHelper.GetMethodDefinition(() => Math.Truncate(default(decimal))), - ReflectionHelper.GetMethodDefinition(() => Math.Truncate(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Abs(default(decimal))), + ReflectHelper.GetMethodDefinition(() => Math.Abs(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Abs(default(float))), + ReflectHelper.GetMethodDefinition(() => Math.Abs(default(long))), + ReflectHelper.GetMethodDefinition(() => Math.Abs(default(int))), + ReflectHelper.GetMethodDefinition(() => Math.Abs(default(short))), + ReflectHelper.GetMethodDefinition(() => Math.Abs(default(sbyte))), - ReflectionHelper.GetMethodDefinition(() => Math.Pow(default(double), default(double))), - }; + ReflectHelper.GetMethodDefinition(() => Math.Sign(default(decimal))), + ReflectHelper.GetMethodDefinition(() => Math.Sign(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Sign(default(float))), + ReflectHelper.GetMethodDefinition(() => Math.Sign(default(long))), + ReflectHelper.GetMethodDefinition(() => Math.Sign(default(int))), + ReflectHelper.GetMethodDefinition(() => Math.Sign(default(short))), + ReflectHelper.GetMethodDefinition(() => Math.Sign(default(sbyte))), + + ReflectHelper.GetMethodDefinition(() => Math.Round(default(decimal))), + ReflectHelper.GetMethodDefinition(() => Math.Round(default(decimal), default(int))), + ReflectHelper.GetMethodDefinition(() => Math.Round(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Round(default(double), default(int))), + ReflectHelper.GetMethodDefinition(() => Math.Floor(default(decimal))), + ReflectHelper.GetMethodDefinition(() => Math.Floor(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Ceiling(default(decimal))), + ReflectHelper.GetMethodDefinition(() => Math.Ceiling(default(double))), + ReflectHelper.GetMethodDefinition(() => Math.Truncate(default(decimal))), + ReflectHelper.GetMethodDefinition(() => Math.Truncate(default(double))), + + ReflectHelper.GetMethodDefinition(() => Math.Pow(default(double), default(double))), + }; } public override HqlTreeNode BuildHql(MethodInfo method, Expression expression, ReadOnlyCollection arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) @@ -72,7 +73,7 @@ public override HqlTreeNode BuildHql(MethodInfo method, Expression expression, R { return treeBuilder.MethodCall(function, firstArgument, visitor.Visit(arguments[1]).AsExpression()); } - + return treeBuilder.MethodCall(function, firstArgument); } } diff --git a/src/NHibernate/Linq/Functions/QueryableGenerator.cs b/src/NHibernate/Linq/Functions/QueryableGenerator.cs index 88165ccb4d1..a0be6bbb5f5 100644 --- a/src/NHibernate/Linq/Functions/QueryableGenerator.cs +++ b/src/NHibernate/Linq/Functions/QueryableGenerator.cs @@ -15,10 +15,10 @@ public AnyHqlGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(() => Queryable.Any(null)), - ReflectionHelper.GetMethodDefinition(() => Queryable.Any(null, null)), - ReflectionHelper.GetMethodDefinition(() => Enumerable.Any(null)), - ReflectionHelper.GetMethodDefinition(() => Enumerable.Any(null, null)) + ReflectHelper.GetMethodDefinition(() => Queryable.Any(null)), + ReflectHelper.GetMethodDefinition(() => Queryable.Any(null, null)), + ReflectHelper.GetMethodDefinition(() => Enumerable.Any(null)), + ReflectHelper.GetMethodDefinition(() => Enumerable.Any(null, null)) }; } @@ -54,8 +54,8 @@ public AllHqlGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(() => Queryable.All(null, null)), - ReflectionHelper.GetMethodDefinition(() => Enumerable.All(null, null)) + ReflectHelper.GetMethodDefinition(() => Queryable.All(null, null)), + ReflectHelper.GetMethodDefinition(() => Enumerable.All(null, null)) }; } @@ -89,8 +89,8 @@ public MinHqlGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(() => Queryable.Min(null)), - ReflectionHelper.GetMethodDefinition(() => Enumerable.Min(null)) + ReflectHelper.GetMethodDefinition(() => Queryable.Min(null)), + ReflectHelper.GetMethodDefinition(() => Enumerable.Min(null)) }; } @@ -106,8 +106,8 @@ public MaxHqlGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(() => Queryable.Max(null)), - ReflectionHelper.GetMethodDefinition(() => Enumerable.Max(null)) + ReflectHelper.GetMethodDefinition(() => Queryable.Max(null)), + ReflectHelper.GetMethodDefinition(() => Enumerable.Max(null)) }; } @@ -143,8 +143,8 @@ public CollectionContainsGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(() => Queryable.Contains(null, null)), - ReflectionHelper.GetMethodDefinition(() => Enumerable.Contains(null, null)) + ReflectHelper.GetMethodDefinition(() => Queryable.Contains(null, null)), + ReflectHelper.GetMethodDefinition(() => Enumerable.Contains(null, null)) }; } diff --git a/src/NHibernate/Linq/Functions/StringGenerator.cs b/src/NHibernate/Linq/Functions/StringGenerator.cs index f70654acfdb..960280e746a 100644 --- a/src/NHibernate/Linq/Functions/StringGenerator.cs +++ b/src/NHibernate/Linq/Functions/StringGenerator.cs @@ -5,6 +5,7 @@ using System.Reflection; using NHibernate.Hql.Ast; using NHibernate.Linq.Visitors; +using NHibernate.Util; namespace NHibernate.Linq.Functions { @@ -63,7 +64,7 @@ public class LengthGenerator : BaseHqlGeneratorForProperty { public LengthGenerator() { - SupportedProperties = new[] { ReflectionHelper.GetProperty((string x) => x.Length) }; + SupportedProperties = new[] { ReflectHelper.GetProperty((string x) => x.Length) }; } public override HqlTreeNode BuildHql(MemberInfo member, Expression expression, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) @@ -76,7 +77,7 @@ public class StartsWithGenerator : BaseHqlGeneratorForMethod { public StartsWithGenerator() { - SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition(x => x.StartsWith(null)) }; + SupportedMethods = new[] { ReflectHelper.GetMethodDefinition(x => x.StartsWith(null)) }; } public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) @@ -93,7 +94,7 @@ public class EndsWithGenerator : BaseHqlGeneratorForMethod { public EndsWithGenerator() { - SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition(x => x.EndsWith(null)) }; + SupportedMethods = new[] { ReflectHelper.GetMethodDefinition(x => x.EndsWith(null)) }; } public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) @@ -110,7 +111,7 @@ public class ContainsGenerator : BaseHqlGeneratorForMethod { public ContainsGenerator() { - SupportedMethods = new[] { ReflectionHelper.GetMethodDefinition(x => x.Contains(null)) }; + SupportedMethods = new[] { ReflectHelper.GetMethodDefinition(x => x.Contains(null)) }; } public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) @@ -130,8 +131,8 @@ public ToLowerGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(x => x.ToLower()), - ReflectionHelper.GetMethodDefinition(x => x.ToLowerInvariant()) + ReflectHelper.GetMethodDefinition(x => x.ToLower()), + ReflectHelper.GetMethodDefinition(x => x.ToLowerInvariant()) }; } @@ -147,8 +148,8 @@ public ToUpperGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(x => x.ToUpper()), - ReflectionHelper.GetMethodDefinition(x => x.ToUpperInvariant()), + ReflectHelper.GetMethodDefinition(x => x.ToUpper()), + ReflectHelper.GetMethodDefinition(x => x.ToUpperInvariant()), }; } @@ -164,8 +165,8 @@ public SubStringGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(s => s.Substring(0)), - ReflectionHelper.GetMethodDefinition(s => s.Substring(0, 0)) + ReflectHelper.GetMethodDefinition(s => s.Substring(0)), + ReflectHelper.GetMethodDefinition(s => s.Substring(0, 0)) }; } @@ -188,10 +189,10 @@ public IndexOfGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(s => s.IndexOf(' ')), - ReflectionHelper.GetMethodDefinition(s => s.IndexOf(" ")), - ReflectionHelper.GetMethodDefinition(s => s.IndexOf(' ', 0)), - ReflectionHelper.GetMethodDefinition(s => s.IndexOf(" ", 0)) + ReflectHelper.GetMethodDefinition(s => s.IndexOf(' ')), + ReflectHelper.GetMethodDefinition(s => s.IndexOf(" ")), + ReflectHelper.GetMethodDefinition(s => s.IndexOf(' ', 0)), + ReflectHelper.GetMethodDefinition(s => s.IndexOf(" ", 0)) }; } public override HqlTreeNode BuildHql(MethodInfo method, Expression targetObject, ReadOnlyCollection arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor) @@ -222,8 +223,8 @@ public ReplaceGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(s => s.Replace(' ', ' ')), - ReflectionHelper.GetMethodDefinition(s => s.Replace("", "")) + ReflectHelper.GetMethodDefinition(s => s.Replace(' ', ' ')), + ReflectHelper.GetMethodDefinition(s => s.Replace("", "")) }; } @@ -242,10 +243,10 @@ public TrimGenerator() { SupportedMethods = new[] { - ReflectionHelper.GetMethodDefinition(s => s.Trim()), - ReflectionHelper.GetMethodDefinition(s => s.Trim('a')), - ReflectionHelper.GetMethodDefinition(s => s.TrimStart('a')), - ReflectionHelper.GetMethodDefinition(s => s.TrimEnd('a')) + ReflectHelper.GetMethodDefinition(s => s.Trim()), + ReflectHelper.GetMethodDefinition(s => s.Trim('a')), + ReflectHelper.GetMethodDefinition(s => s.TrimStart('a')), + ReflectHelper.GetMethodDefinition(s => s.TrimEnd('a')) }; } diff --git a/src/NHibernate/Linq/LinqExtensionMethods.cs b/src/NHibernate/Linq/LinqExtensionMethods.cs index dafee708975..e783502aceb 100755 --- a/src/NHibernate/Linq/LinqExtensionMethods.cs +++ b/src/NHibernate/Linq/LinqExtensionMethods.cs @@ -2,8 +2,10 @@ using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; +using System.Reflection; using NHibernate.Impl; using NHibernate.Type; +using NHibernate.Util; using Remotion.Linq; using Remotion.Linq.Parsing.ExpressionTreeVisitors; @@ -31,36 +33,44 @@ public static IQueryable Query(this IStatelessSession session, string enti return new NhQueryable(session.GetSessionImplementation(), entityName); } + private static readonly MethodInfo CacheableDefinition = ReflectHelper.GetMethodDefinition(() => Cacheable(null)); + public static IQueryable Cacheable(this IQueryable query) { - var method = ReflectionHelper.GetMethodDefinition(() => Cacheable(null)).MakeGenericMethod(typeof(T)); + var method = CacheableDefinition.MakeGenericMethod(typeof(T)); var callExpression = Expression.Call(method, query.Expression); return new NhQueryable(query.Provider, callExpression); } + private static readonly MethodInfo CacheModeDefinition = ReflectHelper.GetMethodDefinition(() => CacheMode(null, NHibernate.CacheMode.Normal)); + public static IQueryable CacheMode(this IQueryable query, CacheMode cacheMode) { - var method = ReflectionHelper.GetMethodDefinition(() => CacheMode(null, NHibernate.CacheMode.Normal)).MakeGenericMethod(typeof(T)); + var method = CacheModeDefinition.MakeGenericMethod(typeof(T)); var callExpression = Expression.Call(method, query.Expression, Expression.Constant(cacheMode)); return new NhQueryable(query.Provider, callExpression); } + private static readonly MethodInfo CacheRegionDefinition = ReflectHelper.GetMethodDefinition(() => CacheRegion(null, null)); + public static IQueryable CacheRegion(this IQueryable query, string region) { - var method = ReflectionHelper.GetMethodDefinition(() => CacheRegion(null, null)).MakeGenericMethod(typeof(T)); + var method = CacheRegionDefinition.MakeGenericMethod(typeof(T)); var callExpression = Expression.Call(method, query.Expression, Expression.Constant(region)); return new NhQueryable(query.Provider, callExpression); } + private static readonly MethodInfo TimeoutDefinition = ReflectHelper.GetMethodDefinition(() => Timeout(null, 0)); + public static IQueryable Timeout(this IQueryable query, int timeout) { - var method = ReflectionHelper.GetMethodDefinition(() => Timeout(null, 0)).MakeGenericMethod(typeof(T)); + var method = TimeoutDefinition.MakeGenericMethod(typeof(T)); var callExpression = Expression.Call(method, query.Expression, Expression.Constant(timeout)); diff --git a/src/NHibernate/Linq/NestedSelects/NestedSelectDetector.cs b/src/NHibernate/Linq/NestedSelects/NestedSelectDetector.cs index 815cf4232f5..0d6639a6ef5 100644 --- a/src/NHibernate/Linq/NestedSelects/NestedSelectDetector.cs +++ b/src/NHibernate/Linq/NestedSelects/NestedSelectDetector.cs @@ -1,8 +1,6 @@ -using System.Collections; using System.Collections.Generic; using System.Linq.Expressions; using System.Reflection; -using NHibernate.Linq.Visitors; using NHibernate.Util; using Remotion.Linq.Clauses.Expressions; using Remotion.Linq.Parsing; @@ -38,7 +36,7 @@ protected override Expression VisitSubQueryExpression(SubQueryExpression express protected override Expression VisitMemberExpression(MemberExpression expression) { - var memberType = expression.Member.GetPropertyOrFieldType(); + var memberType = ReflectHelper.GetPropertyOrFieldType(expression.Member); if (memberType != null && memberType.IsCollectionType() && IsChainedFromQuerySourceReference(expression) diff --git a/src/NHibernate/Linq/NestedSelects/NestedSelectRewriter.cs b/src/NHibernate/Linq/NestedSelects/NestedSelectRewriter.cs index 56a5ded7921..37ab62de54b 100644 --- a/src/NHibernate/Linq/NestedSelects/NestedSelectRewriter.cs +++ b/src/NHibernate/Linq/NestedSelects/NestedSelectRewriter.cs @@ -16,11 +16,15 @@ namespace NHibernate.Linq.NestedSelects static class NestedSelectRewriter { private static readonly MethodInfo CastMethod = - ReflectionHelper.GetMethod(() => Enumerable.Cast(null)); - private static readonly MethodInfo GroupByMethod = ReflectionHelper.GetMethod( + ReflectHelper.GetMethod(() => Enumerable.Cast(null)); + private static readonly MethodInfo GroupByMethod = ReflectHelper.GetMethod( () => Enumerable.GroupBy(null, null, (Func)null)); - private static readonly MethodInfo WhereMethod = ReflectionHelper.GetMethod( - () => Enumerable.Where(null, (Func)null)); + private static readonly MethodInfo WhereMethod = ReflectHelper.GetMethod( + () => Enumerable.Where(null, (Func)null)); + private static readonly MethodInfo ObjectReferenceEquals = ReflectHelper.GetMethod( + () => ReferenceEquals(null, null)); + private static readonly PropertyInfo IGroupingKeyProperty = (PropertyInfo) + ReflectHelper.GetProperty, Tuple>(g => g.Key); public static void ReWrite(QueryModel queryModel, ISessionFactory sessionFactory) { @@ -40,7 +44,7 @@ public static void ReWrite(QueryModel queryModel, ISessionFactory sessionFactory replacements.Add(expression, processed); } - var key = Expression.Property(group, "Key"); + var key = Expression.Property(group, IGroupingKeyProperty); var expressions = new List(); @@ -200,9 +204,7 @@ private static LambdaExpression MakePredicate(int index) var t = Expression.Parameter(typeof (Tuple), "t"); return Expression.Lambda( Expression.Not( - Expression.Call(typeof (object), - "ReferenceEquals", - System.Type.EmptyTypes, + Expression.Call(ObjectReferenceEquals, ArrayIndex(Expression.Property(t, Tuple.ItemsProperty), index), Expression.Constant(null))), t); diff --git a/src/NHibernate/Linq/NhRelinqQueryParser.cs b/src/NHibernate/Linq/NhRelinqQueryParser.cs index 1a667195f6e..4de1dd3d9d1 100644 --- a/src/NHibernate/Linq/NhRelinqQueryParser.cs +++ b/src/NHibernate/Linq/NhRelinqQueryParser.cs @@ -4,16 +4,17 @@ using System.Linq.Expressions; using System.Reflection; using NHibernate.Linq.ExpressionTransformers; +using NHibernate.Linq.Visitors; +using NHibernate.Util; using Remotion.Linq; using Remotion.Linq.Clauses; using Remotion.Linq.Clauses.StreamedData; using Remotion.Linq.EagerFetching.Parsing; using Remotion.Linq.Parsing.ExpressionTreeVisitors.Transformation; using Remotion.Linq.Parsing.Structure; +using Remotion.Linq.Parsing.Structure.ExpressionTreeProcessors; using Remotion.Linq.Parsing.Structure.IntermediateModel; using Remotion.Linq.Parsing.Structure.NodeTypeProviders; -using Remotion.Linq.Parsing.Structure.ExpressionTreeProcessors; -using NHibernate.Linq.Visitors; namespace NHibernate.Linq { @@ -73,38 +74,38 @@ public NHibernateNodeTypeProvider() var methodInfoRegistry = new MethodInfoBasedNodeTypeRegistry(); methodInfoRegistry.Register( - new[] { ReflectionHelper.GetMethodDefinition(() => EagerFetchingExtensionMethods.Fetch(null, null)) }, + new[] { ReflectHelper.GetMethodDefinition(() => EagerFetchingExtensionMethods.Fetch(null, null)) }, typeof(FetchOneExpressionNode)); methodInfoRegistry.Register( - new[] { ReflectionHelper.GetMethodDefinition(() => EagerFetchingExtensionMethods.FetchMany(null, null)) }, + new[] { ReflectHelper.GetMethodDefinition(() => EagerFetchingExtensionMethods.FetchMany(null, null)) }, typeof(FetchManyExpressionNode)); methodInfoRegistry.Register( - new[] { ReflectionHelper.GetMethodDefinition(() => EagerFetchingExtensionMethods.ThenFetch(null, null)) }, + new[] { ReflectHelper.GetMethodDefinition(() => EagerFetchingExtensionMethods.ThenFetch(null, null)) }, typeof(ThenFetchOneExpressionNode)); methodInfoRegistry.Register( - new[] { ReflectionHelper.GetMethodDefinition(() => EagerFetchingExtensionMethods.ThenFetchMany(null, null)) }, + new[] { ReflectHelper.GetMethodDefinition(() => EagerFetchingExtensionMethods.ThenFetchMany(null, null)) }, typeof(ThenFetchManyExpressionNode)); methodInfoRegistry.Register( new[] { - ReflectionHelper.GetMethodDefinition(() => LinqExtensionMethods.Cacheable(null)), - ReflectionHelper.GetMethodDefinition(() => LinqExtensionMethods.CacheMode(null, CacheMode.Normal)), - ReflectionHelper.GetMethodDefinition(() => LinqExtensionMethods.CacheRegion(null, null)), + ReflectHelper.GetMethodDefinition(() => LinqExtensionMethods.Cacheable(null)), + ReflectHelper.GetMethodDefinition(() => LinqExtensionMethods.CacheMode(null, CacheMode.Normal)), + ReflectHelper.GetMethodDefinition(() => LinqExtensionMethods.CacheRegion(null, null)), }, typeof(CacheableExpressionNode)); methodInfoRegistry.Register( new[] { - ReflectionHelper.GetMethodDefinition(() => Queryable.AsQueryable(null)), - ReflectionHelper.GetMethodDefinition(() => Queryable.AsQueryable(null)), + ReflectHelper.GetMethodDefinition(() => Queryable.AsQueryable(null)), + ReflectHelper.GetMethodDefinition(() => Queryable.AsQueryable(null)), }, typeof(AsQueryableExpressionNode) ); methodInfoRegistry.Register( new[] { - ReflectionHelper.GetMethodDefinition(() => LinqExtensionMethods.Timeout(null, 0)), + ReflectHelper.GetMethodDefinition(() => LinqExtensionMethods.Timeout(null, 0)), }, typeof (TimeoutExpressionNode) ); diff --git a/src/NHibernate/Linq/Visitors/ExpressionParameterVisitor.cs b/src/NHibernate/Linq/Visitors/ExpressionParameterVisitor.cs index dae61148f78..cc3662fb149 100644 --- a/src/NHibernate/Linq/Visitors/ExpressionParameterVisitor.cs +++ b/src/NHibernate/Linq/Visitors/ExpressionParameterVisitor.cs @@ -6,6 +6,7 @@ using NHibernate.Engine; using NHibernate.Param; using NHibernate.Type; +using NHibernate.Util; using Remotion.Linq.Parsing; namespace NHibernate.Linq.Visitors @@ -19,13 +20,13 @@ public class ExpressionParameterVisitor : ExpressionTreeVisitor private readonly ISessionFactoryImplementor _sessionFactory; private static readonly MethodInfo QueryableSkipDefinition = - ReflectionHelper.GetMethodDefinition(() => Queryable.Skip(null, 0)); + ReflectHelper.GetMethodDefinition(() => Queryable.Skip(null, 0)); private static readonly MethodInfo QueryableTakeDefinition = - ReflectionHelper.GetMethodDefinition(() => Queryable.Take(null, 0)); + ReflectHelper.GetMethodDefinition(() => Queryable.Take(null, 0)); private static readonly MethodInfo EnumerableSkipDefinition = - ReflectionHelper.GetMethodDefinition(() => Enumerable.Skip(null, 0)); + ReflectHelper.GetMethodDefinition(() => Enumerable.Skip(null, 0)); private static readonly MethodInfo EnumerableTakeDefinition = - ReflectionHelper.GetMethodDefinition(() => Enumerable.Take(null, 0)); + ReflectHelper.GetMethodDefinition(() => Enumerable.Take(null, 0)); private readonly ICollection _pagingMethods = new HashSet { diff --git a/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessFirst.cs b/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessFirst.cs index 9d1de474209..b41635148a2 100644 --- a/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessFirst.cs +++ b/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessFirst.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Reflection; +using NHibernate.Util; using Remotion.Linq.Clauses.ResultOperators; namespace NHibernate.Linq.Visitors.ResultOperatorProcessors @@ -7,9 +8,9 @@ namespace NHibernate.Linq.Visitors.ResultOperatorProcessors public class ProcessFirst : ProcessFirstOrSingleBase, IResultOperatorProcessor { private static readonly MethodInfo FirstOrDefault = - ReflectionHelper.GetMethodDefinition(() => Queryable.FirstOrDefault(null)); + ReflectHelper.GetMethodDefinition(() => Queryable.FirstOrDefault(null)); private static readonly MethodInfo First = - ReflectionHelper.GetMethodDefinition(() => Queryable.First(null)); + ReflectHelper.GetMethodDefinition(() => Queryable.First(null)); public void Process(FirstResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree) { diff --git a/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSingle.cs b/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSingle.cs index 494469a3e32..fde0a7f23ca 100644 --- a/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSingle.cs +++ b/src/NHibernate/Linq/Visitors/ResultOperatorProcessors/ProcessSingle.cs @@ -1,5 +1,6 @@ using System.Linq; using System.Reflection; +using NHibernate.Util; using Remotion.Linq.Clauses.ResultOperators; namespace NHibernate.Linq.Visitors.ResultOperatorProcessors @@ -7,9 +8,9 @@ namespace NHibernate.Linq.Visitors.ResultOperatorProcessors public class ProcessSingle : ProcessFirstOrSingleBase, IResultOperatorProcessor { private static readonly MethodInfo SingleOrDefault = - ReflectionHelper.GetMethodDefinition(() => Queryable.SingleOrDefault(null)); + ReflectHelper.GetMethodDefinition(() => Queryable.SingleOrDefault(null)); private static readonly MethodInfo Single = - ReflectionHelper.GetMethodDefinition(() => Queryable.Single(null)); + ReflectHelper.GetMethodDefinition(() => Queryable.Single(null)); public void Process(SingleResultOperator resultOperator, QueryModelVisitor queryModelVisitor, IntermediateHqlTree tree) { diff --git a/src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs b/src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs index a7ddb2a04c0..c161402090d 100644 --- a/src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs +++ b/src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs @@ -19,7 +19,7 @@ internal class DefaultMethodEmitter : IMethodBodyEmitter { private static readonly MethodInfo getInterceptor; - private static readonly MethodInfo handlerMethod = ReflectionHelper.GetMethod( + private static readonly MethodInfo handlerMethod = ReflectHelper.GetMethod( i => i.Intercept(null)); private static readonly MethodInfo getArguments = typeof(InvocationInfo).GetMethod("get_Arguments"); diff --git a/src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs b/src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs index 8bc6679bfa8..f9ada32457b 100644 --- a/src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs +++ b/src/NHibernate/Proxy/DynamicProxy/ProxyFactory.cs @@ -21,11 +21,11 @@ public sealed class ProxyFactory { private static readonly ConstructorInfo defaultBaseConstructor = typeof(object).GetConstructor(new System.Type[0]); - private static readonly MethodInfo getValue = ReflectionHelper.GetMethod( + private static readonly MethodInfo getValue = ReflectHelper.GetMethod( si => si.GetValue(null, null)); - private static readonly MethodInfo setType = ReflectionHelper.GetMethod( + private static readonly MethodInfo setType = ReflectHelper.GetMethod( si => si.SetType(null)); - private static readonly MethodInfo addValue = ReflectionHelper.GetMethod( + private static readonly MethodInfo addValue = ReflectHelper.GetMethod( si => si.AddValue(null, null)); public ProxyFactory() diff --git a/src/NHibernate/Type/TypeFactory.cs b/src/NHibernate/Type/TypeFactory.cs index 910854f0fce..6695fa2daa1 100644 --- a/src/NHibernate/Type/TypeFactory.cs +++ b/src/NHibernate/Type/TypeFactory.cs @@ -39,23 +39,23 @@ private enum TypeClassification private static readonly char[] LengthSplit = new[] { '(', ')' }; private static readonly TypeFactory Instance; - private static readonly MethodInfo BagDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo BagDefinition = ReflectHelper.GetMethodDefinition( f => f.Bag(null, null)); - private static readonly MethodInfo IdBagDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo IdBagDefinition = ReflectHelper.GetMethodDefinition( f => f.IdBag(null, null)); - private static readonly MethodInfo ListDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo ListDefinition = ReflectHelper.GetMethodDefinition( f => f.List(null, null)); - private static readonly MethodInfo MapDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo MapDefinition = ReflectHelper.GetMethodDefinition( f => f.Map(null, null)); - private static readonly MethodInfo SortedListDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo SortedListDefinition = ReflectHelper.GetMethodDefinition( f => f.SortedList(null, null, null)); - private static readonly MethodInfo SortedDictionaryDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo SortedDictionaryDefinition = ReflectHelper.GetMethodDefinition( f => f.SortedDictionary(null, null, null)); - private static readonly MethodInfo SetDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo SetDefinition = ReflectHelper.GetMethodDefinition( f => f.Set(null, null)); - private static readonly MethodInfo SortedSetDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo SortedSetDefinition = ReflectHelper.GetMethodDefinition( f => f.SortedSet(null, null, null)); - private static readonly MethodInfo OrderedSetDefinition = ReflectionHelper.GetMethodDefinition( + private static readonly MethodInfo OrderedSetDefinition = ReflectHelper.GetMethodDefinition( f => f.OrderedSet(null, null)); /* diff --git a/src/NHibernate/Util/ReflectHelper.cs b/src/NHibernate/Util/ReflectHelper.cs index 64536f9617e..d8e0d3b9a57 100644 --- a/src/NHibernate/Util/ReflectHelper.cs +++ b/src/NHibernate/Util/ReflectHelper.cs @@ -2,6 +2,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; +using System.Linq.Expressions; using System.Reflection; using System.Text; @@ -26,6 +27,91 @@ public static class ReflectHelper private static readonly MethodInfo Exception_InternalPreserveStackTrace = typeof(Exception).GetMethod("InternalPreserveStackTrace", BindingFlags.Instance | BindingFlags.NonPublic); + /// + /// Extract the from a given expression. + /// + /// The declaring-type of the method. + /// The method. + /// The of the no-generic method or the generic-definition for a generic-method. + /// + public static MethodInfo GetMethodDefinition(Expression> method) + { + MethodInfo methodInfo = GetMethod(method); + return methodInfo.IsGenericMethod ? methodInfo.GetGenericMethodDefinition() : methodInfo; + } + + /// + /// Extract the from a given expression. + /// + /// The declaring-type of the method. + /// The method. + /// The of the method. + public static MethodInfo GetMethod(Expression> method) + { + if (method == null) + throw new ArgumentNullException("method"); + + return ((MethodCallExpression)method.Body).Method; + } + + /// + /// Extract the from a given expression. + /// + /// The method. + /// The of the no-generic method or the generic-definition for a generic-method. + /// + public static MethodInfo GetMethodDefinition(Expression method) + { + MethodInfo methodInfo = GetMethod(method); + return methodInfo.IsGenericMethod ? methodInfo.GetGenericMethodDefinition() : methodInfo; + } + + /// + /// Extract the from a given expression. + /// + /// The method. + /// The of the method. + public static MethodInfo GetMethod(Expression method) + { + if (method == null) + throw new ArgumentNullException("method"); + + return ((MethodCallExpression)method.Body).Method; + } + + /// + /// Gets the field or property to be accessed. + /// + /// The declaring-type of the property. + /// The type of the property. + /// The expression representing the property getter. + /// The of the property. + public static MemberInfo GetProperty(Expression> property) + { + if (property == null) + { + throw new ArgumentNullException("property"); + } + return ((MemberExpression)property.Body).Member; + } + + internal static System.Type GetPropertyOrFieldType(this MemberInfo memberInfo) + { + var propertyInfo = memberInfo as PropertyInfo; + if (propertyInfo != null) + { + return propertyInfo.PropertyType; + } + + var fieldInfo = memberInfo as FieldInfo; + if (fieldInfo != null) + { + return fieldInfo.FieldType; + } + + return null; + } + /// /// Determine if the specified overrides the /// implementation of Equals from @@ -565,7 +651,7 @@ internal static object GetConstantValue(string qualifiedName, ISessionFactoryImp return null; } - [Obsolete("Please use Linq.ReflectionHelper instead")] + [Obsolete("Please use GetMethodDefinition then MethodInfo.MakeGenericMethod instead")] public static MethodInfo GetGenericMethodFrom(string methodName, System.Type[] genericArgs, System.Type[] signature) { MethodInfo result = null; diff --git a/src/NHibernate/Util/ReflectionCache.cs b/src/NHibernate/Util/ReflectionCache.cs index 767a17d0b8b..1b9afacbfac 100644 --- a/src/NHibernate/Util/ReflectionCache.cs +++ b/src/NHibernate/Util/ReflectionCache.cs @@ -20,40 +20,40 @@ internal static class ReflectionCache internal static class EnumerableMethods { internal static readonly MethodInfo AggregateDefinition = - ReflectionHelper.GetMethodDefinition(() => Enumerable.Aggregate(null, null)); + ReflectHelper.GetMethodDefinition(() => Enumerable.Aggregate(null, null)); internal static readonly MethodInfo AggregateWithSeedDefinition = - ReflectionHelper.GetMethodDefinition(() => Enumerable.Aggregate(null, null, null)); + ReflectHelper.GetMethodDefinition(() => Enumerable.Aggregate(null, null, null)); internal static readonly MethodInfo AggregateWithSeedAndResultSelectorDefinition = - ReflectionHelper.GetMethodDefinition(() => Enumerable.Aggregate(null, null, null, null)); + ReflectHelper.GetMethodDefinition(() => Enumerable.Aggregate(null, null, null, null)); internal static readonly MethodInfo CastDefinition = - ReflectionHelper.GetMethodDefinition(() => Enumerable.Cast(null)); + ReflectHelper.GetMethodDefinition(() => Enumerable.Cast(null)); - internal static readonly MethodInfo GroupByWithElementSelectorDefinition = ReflectionHelper.GetMethodDefinition( - () => Enumerable.GroupBy(null, null, (Func)null)); + internal static readonly MethodInfo GroupByWithElementSelectorDefinition = ReflectHelper.GetMethodDefinition( + () => Enumerable.GroupBy(null, null, default(Func))); internal static readonly MethodInfo SelectDefinition = - ReflectionHelper.GetMethodDefinition(() => Enumerable.Select(null, (Func)null)); + ReflectHelper.GetMethodDefinition(() => Enumerable.Select(null, default(Func))); internal static readonly MethodInfo ToArrayDefinition = - ReflectionHelper.GetMethodDefinition(() => Enumerable.ToArray(null)); + ReflectHelper.GetMethodDefinition(() => Enumerable.ToArray(null)); internal static readonly MethodInfo ToListDefinition = - ReflectionHelper.GetMethodDefinition(() => Enumerable.ToList(null)); + ReflectHelper.GetMethodDefinition(() => Enumerable.ToList(null)); } internal static class MethodBaseMethods { internal static readonly MethodInfo GetMethodFromHandle = - ReflectionHelper.GetMethod(() => MethodBase.GetMethodFromHandle(new RuntimeMethodHandle())); + ReflectHelper.GetMethod(() => MethodBase.GetMethodFromHandle(new RuntimeMethodHandle())); internal static readonly MethodInfo GetMethodFromHandleWithDeclaringType = - ReflectionHelper.GetMethod(() => MethodBase.GetMethodFromHandle(new RuntimeMethodHandle(), new RuntimeTypeHandle())); + ReflectHelper.GetMethod(() => MethodBase.GetMethodFromHandle(new RuntimeMethodHandle(), new RuntimeTypeHandle())); } internal static class TypeMethods { internal static readonly MethodInfo GetTypeFromHandle = - ReflectionHelper.GetMethod(() => System.Type.GetTypeFromHandle(new RuntimeTypeHandle())); + ReflectHelper.GetMethod(() => System.Type.GetTypeFromHandle(new RuntimeTypeHandle())); } } } \ No newline at end of file