-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add support for using extension methods in bindings #931
Conversation
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.
Very nice :)
To use custom extension methods you can:
This needs to be then registered using dependency injection. If user registers no implementation, DotVVM uses the |
src/DotVVM.Framework.Tests.Common/Binding/CustomExtensionMethodTests.cs
Outdated
Show resolved
Hide resolved
if (members.Length == 0) | ||
{ | ||
// We did not find any match in regular methods => try extension methods | ||
var extensions = extensionsProvider.GetExtensionMethods() |
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.
Shall we cache this? I am afraid that this will browse the types and look for the methods every single time.
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.
We probably should. The implementation now caches the result of the method call GetMethods(..)
to avoid unnecessary reflection. Also the attribute ExtensionAttribute
is now checked to ensure that we yield only extension methods
This PR allows using extension methods inside bindings. #903 should be merged first.
TypeRegistry
Currently the only registered type to look for extension methods is
System.Linq.Enumerable
. This makes it easier to define lambdas when using LINQ.Enumerable.Where(Array, (int item) => item % 2 == 0)
Array.Where((int item) => item % 2 == 0)