-
Notifications
You must be signed in to change notification settings - Fork 934
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
NH-3952: removing usages of NHibernate.Linq.EnumerableHelper #557
Conversation
…eflection pattern to stick with this refactoring.
There is slightly more performant version than "Cached method definition + make gen" exists.
The idea that you extract a method from a bare "Method group delegate". |
Thanks for the suggestion, The case "cached method definition + make gen" should not be used if we can simply use a "cached method". I have done so in this pull request commits. Now, actually ReflectionHelper use another technique for getting a MethodInfo, like:
Should we change this in favor of your About the quite "blunt" performance test on the other current patterns I have found in
So your method looks actually better than the one in place in ReflectionHelper. Currently, on code I have modified, I use in order of priority whenever possible:
And that is all. Replacing I may instead introduce those two methods on What do you think of this please? |
And well, my point on "performances" was more on choosing to which pattern already in use I should stick for cleaning up usages of |
|
||
// TODO rename / remove - reflection helper above is better | ||
[Obsolete("ReflectionHelper is better")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change to [Obsolete("Please use ReflectionHelper instead")]
@@ -16,7 +16,18 @@ namespace NHibernate.Linq.NestedSelects | |||
{ | |||
static class NestedSelectRewriter | |||
{ | |||
private static readonly MethodInfo CastMethod = EnumerableHelper.GetMethod("Cast", new[] { typeof (IEnumerable) }, new[] { typeof (object[]) }); | |||
private static readonly MethodInfo CastMethod = ReflectionHelper.GetMethod( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love these fields to be concentrated in EnumerableHelper
class (as internal static readonly
fields), or other class, if we are making EnumerableHelper
obsolete.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to check if a sound naming convention would do. With overloads and methods having the same name but belonging to other types, putting them all on ReflectionHelper
could end up a bit messy.
Maybe should we use some ReflectionHelper
internal subclass for each commonly reflected type to hold their cached method definition. I will test that soon.
The I have added a To avoid ambiguity with overloads, I have put in place a naming convention. It is not really simple. Here is how I have documented it in code:
I have considered the The above naming will not be enough for disambiguation of overloads having same parameter names but different parameter types without being generic. We should probably use type names instead of parameter names for those cases. I still favor parameter names when possible because I find it more readable and generally more concise than type names. (Imagine type name of a resultSelector...) |
var selectMethod = EnumerableHelper.GetMethod("Select", | ||
new[] { typeof (IEnumerable<>), typeof (Func<,>) }, | ||
new[] { typeof (Tuple), elementType }); | ||
var selectMethod = SelectMethodDefinition.MakeGenericMethod(new[] { typeof(Tuple), elementType }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this use ReflectionCache.EnumerableMethods.SelectMethodDefinition
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, missed it.
|
||
internal static readonly MethodInfo CastDefinition = | ||
ReflectionHelper.GetMethodDefinition(() => Enumerable.Cast<object>(null)); | ||
internal static readonly MethodInfo CastOnObjectArray = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs to be moved back to NestedSelectRewriter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was unsure about that one, agreed.
@@ -94,7 +93,46 @@ internal static System.Type GetPropertyOrFieldType(this MemberInfo memberInfo) | |||
} | |||
} | |||
|
|||
// TODO rename / remove - reflection helper above is better | |||
internal static class ReflectionCache |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this to a separate class in NHibernate.Util
namespace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Way more cleaner.
Changes done. Should I rebase for merging commits/cleaning up history? (I prefer to wait for review rather than doing it at once, as this would not help reviewer to review only last changes.) |
Yes, please squash all your changes down to one commit. |
Don't worry, I squashed myself. |
Ok, thanks. |
NHibernate.Linq.EnumerableHelper
has following comment:Done with this pull request.
It includes some additional test cases for classes impacted by this change which were not already thoroughly tested by existing test cases.
An explicit test for choosing which reflection implementation to choose from the other patterns found in NHibernate has been added too. (Unsurprisingly, caching as a static variable the thread safe
MethodInfo
prove to be the fastest by a wide margin. As it does not look to me as an added code complexity, pattern used in this pull request on each class affected by the removal ofEnumerableHelper
.)Tracked under Jira task NH-3952.
EnumerableHelper
is not removed but just marked asObsolete
, since it is publicly exposed and may be directly referenced by NHibernate users.