Skip to content

NH-3964 - obsolete Linq.ReflectionHelper in favor of Util.ReflectHelper. #586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/reference/modules/query_linq.xml
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ IList<Cat> cats =
{
SupportedMethods = new[]
{
ReflectionHelper.GetMethodDefinition(() => NullableExtensions.AsNullable(0))
ReflectHelper.GetMethodDefinition(() => NullableExtensions.AsNullable(0))
};
}
Expand Down
7 changes: 3 additions & 4 deletions src/NHibernate.Test/Linq/BooleanMethodExtensionExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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,
Expand All @@ -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());
}
}
Expand Down
8 changes: 3 additions & 5 deletions src/NHibernate.Test/Linq/CustomExtensionsExample.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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());
}
}
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using NHibernate.Linq;
using NHibernate.Linq.Functions;
using NHibernate.Util;

namespace NHibernate.Test.NHSpecificTest.EntityWithUserTypeCanHaveLinqGenerators
{
public class EntityWithUserTypePropertyGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry
{
public EntityWithUserTypePropertyGeneratorsRegistry()
{
RegisterGenerator(ReflectionHelper.GetMethod((IExample e) => e.IsEquivalentTo(null)),
RegisterGenerator(ReflectHelper.GetMethod((IExample e) => e.IsEquivalentTo(null)),
new EntityWithUserTypePropertyIsEquivalentGenerator());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
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
{
public class EntityWithUserTypePropertyIsEquivalentGenerator : BaseHqlGeneratorForMethod
{
public EntityWithUserTypePropertyIsEquivalentGenerator()
{
SupportedMethods = new[] {ReflectionHelper.GetMethodDefinition((IExample e) => e.IsEquivalentTo(null))};
SupportedMethods = new[] {ReflectHelper.GetMethodDefinition((IExample e) => e.IsEquivalentTo(null))};
}

public override HqlTreeNode BuildHql(
Expand Down
9 changes: 3 additions & 6 deletions src/NHibernate.Test/NHSpecificTest/NH2318/LinqMapping.cs
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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)),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
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
{
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<Expression> arguments, HqlTreeBuilder treeBuilder, IHqlExpressionVisitor visitor)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using NHibernate.Linq;
using NHibernate.Linq.Functions;
using NHibernate.Util;

namespace NHibernate.Test.NHSpecificTest.NH2869
{
public class MyLinqToHqlGeneratorsRegistry : DefaultLinqToHqlGeneratorsRegistry
{
public MyLinqToHqlGeneratorsRegistry()
{
RegisterGenerator(ReflectionHelper.GetMethodDefinition(() => MyLinqExtensions.IsOneInDbZeroInLocal(null, null)), new IsTrueInDbFalseInLocalGenerator());
RegisterGenerator(ReflectHelper.GetMethodDefinition(() => MyLinqExtensions.IsOneInDbZeroInLocal(null, null)), new IsTrueInDbFalseInLocalGenerator());
}
}
}
3 changes: 2 additions & 1 deletion src/NHibernate.Test/NHSpecificTest/NH3604/FixtureByCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,7 +24,7 @@ protected override HbmMapping GetMappings()

mapper.Class<EntityDetail>(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);
});
Expand Down
13 changes: 7 additions & 6 deletions src/NHibernate.Test/NHSpecificTest/NH3952/Fixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Reflection;
using NHibernate.Linq;
using NHibernate.Util;
using NUnit.Framework;

namespace NHibernate.Test.NHSpecificTest.NH3952
Expand Down Expand Up @@ -83,10 +84,10 @@ public void ArraySelect()
}
}

private static readonly MethodInfo CastMethodDefinition = ReflectionHelper.GetMethodDefinition(
private static readonly MethodInfo CastMethodDefinition = ReflectHelper.GetMethodDefinition(
() => Enumerable.Cast<object>(null));

private static readonly MethodInfo CastMethod = ReflectionHelper.GetMethod(
private static readonly MethodInfo CastMethod = ReflectHelper.GetMethod(
() => Enumerable.Cast<int>(null));

[Test, Explicit("Just a blunt perf comparison among some reflection patterns used in NH")]
Expand Down Expand Up @@ -132,7 +133,7 @@ public void ReflectionBluntPerfCompare()
swRefl.Start();
for (var i = 0; i < 1000; i++)
{
var cast = ReflectionHelper.GetMethod(() => Enumerable.Cast<int>(null));
var cast = ReflectHelper.GetMethod(() => Enumerable.Cast<int>(null));
Trace.TraceInformation(cast.ToString());
}
swRefl.Stop();
Expand All @@ -141,7 +142,7 @@ public void ReflectionBluntPerfCompare()
swReflDef.Start();
for (var i = 0; i < 1000; i++)
{
var cast = ReflectionHelper.GetMethodDefinition(() => Enumerable.Cast<object>(null))
var cast = ReflectHelper.GetMethodDefinition(() => Enumerable.Cast<object>(null))
.MakeGenericMethod(new[] { typeof(int) });
Trace.TraceInformation(cast.ToString());
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ public void WhenNullMethodInfoThenThrows()
[Test]
public void WhenNullTypeThenThrows()
{
var methodInfo = ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5));
var methodInfo = ReflectHelper.GetMethodDefinition<List<int>>(t => t.Contains(5));
Assert.Throws<ArgumentNullException>(() => methodInfo.IsMethodOf(null));
}

[Test]
public void WhenDeclaringTypeMatchThenTrue()
{
Assert.That(ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).IsMethodOf(typeof(List<int>)), Is.True);
Assert.That(ReflectHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).IsMethodOf(typeof(List<int>)), Is.True);
}

private class MyCollection: List<int>
Expand All @@ -36,33 +36,33 @@ private class MyCollection: List<int>
[Test]
public void WhenCustomTypeMatchThenTrue()
{
Assert.That(ReflectionHelper.GetMethodDefinition<MyCollection>(t => t.Contains(5)).IsMethodOf(typeof(List<int>)), Is.True);
Assert.That(ReflectHelper.GetMethodDefinition<MyCollection>(t => t.Contains(5)).IsMethodOf(typeof(List<int>)), Is.True);
}

[Test]
public void WhenTypeIsGenericDefinitionAndMatchThenTrue()
{
Assert.That(ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).IsMethodOf(typeof(List<>)), Is.True);
Assert.That(ReflectHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).IsMethodOf(typeof(List<>)), Is.True);
}

[Test]
public void WhenTypeIsGenericImplementedInterfaceAndMatchThenTrue()
{
var containsMethodDefinition = ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5));
var containsMethodDefinition = ReflectHelper.GetMethodDefinition<List<int>>(t => t.Contains(5));
Assert.That(containsMethodDefinition.IsMethodOf(typeof(ICollection<int>)), Is.True);
}

[Test]
public void WhenTypeIsGenericImplementedInterfaceAndMatchGenericInterfaceDefinitionThenTrue()
{
var containsMethodDefinition = ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5));
var containsMethodDefinition = ReflectHelper.GetMethodDefinition<List<int>>(t => t.Contains(5));
Assert.That(containsMethodDefinition.IsMethodOf(typeof(ICollection<>)), Is.True);
}

[Test]
public void WhenNoMatchThenFalse()
{
Assert.That(ReflectionHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).IsMethodOf(typeof(IEnumerable<>)), Is.False);
Assert.That(ReflectHelper.GetMethodDefinition<List<int>>(t => t.Contains(5)).IsMethodOf(typeof(IEnumerable<>)), Is.False);
}

private abstract class MyAbstractClass<T>
Expand All @@ -78,14 +78,14 @@ private class MyClass : MyAbstractClass<int>
[Test]
public void WhenTypeIsGenericImplementedAbstractAndMatchThenTrue()
{
var containsMethodDefinition = ReflectionHelper.GetMethodDefinition<MyClass>(t => t.MyMethod());
var containsMethodDefinition = ReflectHelper.GetMethodDefinition<MyClass>(t => t.MyMethod());
Assert.That(containsMethodDefinition.IsMethodOf(typeof(MyAbstractClass<int>)), Is.True);
}

[Test]
public void WhenTypeIsGenericImplementedAbstractAndMatchGenericInterfaceDefinitionThenTrue()
{
var containsMethodDefinition = ReflectionHelper.GetMethodDefinition<MyClass>(t => t.MyMethod());
var containsMethodDefinition = ReflectHelper.GetMethodDefinition<MyClass>(t => t.MyMethod());
Assert.That(containsMethodDefinition.IsMethodOf(typeof(MyAbstractClass<>)), Is.True);
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/NHibernate.Test/UtilityTest/ReflectionHelperTest.cs
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -19,55 +19,55 @@ public void GenericMethod<T>() { }
[Test]
public void WhenGetMethodForNullThenThrows()
{
Assert.That(() => ReflectionHelper.GetMethodDefinition((Expression<System.Action>) null), Throws.TypeOf<ArgumentNullException>());
Assert.That(() => ReflectHelper.GetMethodDefinition((Expression<System.Action>) null), Throws.TypeOf<ArgumentNullException>());
}

[Test]
public void WhenGenericGetMethodForNullThenThrows()
{
Assert.That(() => ReflectionHelper.GetMethodDefinition<object>((Expression<System.Action<object>>)null), Throws.TypeOf<ArgumentNullException>());
Assert.That(() => ReflectHelper.GetMethodDefinition<object>((Expression<System.Action<object>>)null), Throws.TypeOf<ArgumentNullException>());
}

[Test]
public void WhenGetPropertyForNullThenThrows()
{
Assert.That(() => ReflectionHelper.GetProperty<object, object>(null), Throws.TypeOf<ArgumentNullException>());
Assert.That(() => ReflectHelper.GetProperty<object, object>(null), Throws.TypeOf<ArgumentNullException>());
}

[Test]
public void WhenGenericMethodOfClassThenReturnGenericDefinition()
{
Assert.That(ReflectionHelper.GetMethodDefinition<MyClass>(mc => mc.GenericMethod<int>()), Is.EqualTo(typeof (MyClass).GetMethod("GenericMethod").GetGenericMethodDefinition()));
Assert.That(ReflectHelper.GetMethodDefinition<MyClass>(mc => mc.GenericMethod<int>()), Is.EqualTo(typeof (MyClass).GetMethod("GenericMethod").GetGenericMethodDefinition()));
}

[Test]
public void WhenNoGenericMethodOfClassThenReturnDefinition()
{
Assert.That(ReflectionHelper.GetMethodDefinition<MyClass>(mc => mc.NoGenericMethod()), Is.EqualTo(typeof(MyClass).GetMethod("NoGenericMethod")));
Assert.That(ReflectHelper.GetMethodDefinition<MyClass>(mc => mc.NoGenericMethod()), Is.EqualTo(typeof(MyClass).GetMethod("NoGenericMethod")));
}

[Test]
public void WhenStaticGenericMethodThenReturnGenericDefinition()
{
Assert.That(ReflectionHelper.GetMethodDefinition(() => Enumerable.All<int>(null, null)), Is.EqualTo(typeof(Enumerable).GetMethod("All").GetGenericMethodDefinition()));
Assert.That(ReflectHelper.GetMethodDefinition(() => Enumerable.All<int>(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<MyClass, string>(mc => mc.BaseProperty), Is.EqualTo(typeof(MyClass).GetProperty("BaseProperty")));
Assert.That(ReflectHelper.GetProperty<MyClass, string>(mc => mc.BaseProperty), Is.EqualTo(typeof(MyClass).GetProperty("BaseProperty")));
}

[Test]
public void WhenGetPropertyForBoolThenReturnPropertyInfo()
{
Assert.That(ReflectionHelper.GetProperty<MyClass, bool>(mc => mc.BaseBool), Is.EqualTo(typeof(MyClass).GetProperty("BaseBool")));
Assert.That(ReflectHelper.GetProperty<MyClass, bool>(mc => mc.BaseBool), Is.EqualTo(typeof(MyClass).GetProperty("BaseBool")));
}
}
}
2 changes: 1 addition & 1 deletion src/NHibernate/Bytecode/EmitUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading