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 remapping extensions for core #17918
Closed
Closed
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ public static class PropertyMapperExtensions | |
/// <param name="propertyMapper">The property mapper in which to change the mapping.</param> | ||
/// <param name="key">The name of the property.</param> | ||
/// <param name="method">The modified method to call when the property is updated.</param> | ||
public static void ModifyMapping<TVirtualView, TViewHandler>(this IPropertyMapper<TVirtualView, TViewHandler> propertyMapper, | ||
#pragma warning disable RS0016 // Add public types and members to the declared API | ||
public static IPropertyMapper<TVirtualView, TViewHandler> ModifyMapping<TVirtualView, TViewHandler>(this IPropertyMapper<TVirtualView, TViewHandler> propertyMapper, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if this is breaking... I think methods can't be overloaded just by return type, so this may actually work. I'll test and report back. |
||
string key, Action<TViewHandler, TVirtualView, Action<IElementHandler, IElement>?> method) | ||
where TVirtualView : IElement where TViewHandler : IElementHandler | ||
{ | ||
|
@@ -24,6 +25,7 @@ void newMethod(TViewHandler handler, TVirtualView view) | |
} | ||
|
||
propertyMapper.Add(key, newMethod); | ||
return propertyMapper; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -34,7 +36,7 @@ void newMethod(TViewHandler handler, TVirtualView view) | |
/// <param name="propertyMapper">The property mapper in which to change the mapping.</param> | ||
/// <param name="key">The name of the property.</param> | ||
/// <param name="method">The modified method to call when the property is updated.</param> | ||
public static void ModifyMapping<TVirtualView, TViewHandler>(this IPropertyMapper<IElement, IElementHandler> propertyMapper, | ||
public static IPropertyMapper<IElement, IElementHandler> ModifyMapping<TVirtualView, TViewHandler>(this IPropertyMapper<IElement, IElementHandler> propertyMapper, | ||
string key, Action<TViewHandler, TVirtualView, Action<IElementHandler, IElement>?> method) | ||
where TVirtualView : IElement where TViewHandler : IElementHandler | ||
{ | ||
|
@@ -49,6 +51,7 @@ void newMethod(IElementHandler handler, IElement view) | |
} | ||
|
||
propertyMapper.Add(key, newMethod); | ||
return propertyMapper; | ||
} | ||
|
||
/// <summary> | ||
|
@@ -59,11 +62,26 @@ void newMethod(IElementHandler handler, IElement view) | |
/// <param name="propertyMapper">The property mapper in which to change the mapping.</param> | ||
/// <param name="key">The name of the property.</param> | ||
/// <param name="method">The modified method to call when the property is updated.</param> | ||
public static void ReplaceMapping<TVirtualView, TViewHandler>(this IPropertyMapper<IElement, IElementHandler> propertyMapper, | ||
public static IPropertyMapper<IElement, IElementHandler> ReplaceMapping<TVirtualView, TViewHandler>(this IPropertyMapper<IElement, IElementHandler> propertyMapper, | ||
string key, Action<TViewHandler, TVirtualView> method) | ||
where TVirtualView : IElement where TViewHandler : IElementHandler | ||
{ | ||
propertyMapper.ModifyMapping<TVirtualView, TViewHandler>(key, (h, v, p) => method.Invoke(h, v)); | ||
return propertyMapper.ModifyMapping<TVirtualView, TViewHandler>(key, (h, v, p) => method.Invoke(h, v)); | ||
} | ||
|
||
internal static IPropertyMapper<TVirtualView, TViewHandler> ReplaceMapping<TVirtualView, TViewHandler>(this IPropertyMapper<TVirtualView, TViewHandler> propertyMapper, | ||
string key, Action<TViewHandler, TVirtualView> method) | ||
where TVirtualView : IElement where TViewHandler : IElementHandler | ||
{ | ||
var previousMethod = propertyMapper.GetProperty(key); | ||
|
||
if (previousMethod is null) | ||
{ | ||
propertyMapper.Add(key, method); | ||
return propertyMapper; | ||
} | ||
|
||
return propertyMapper.ModifyMapping(key, (h, v, p) => method.Invoke(h, v)); | ||
} | ||
|
||
/// <summary> | ||
|
@@ -74,11 +92,11 @@ void newMethod(IElementHandler handler, IElement view) | |
/// <param name="propertyMapper">The property mapper in which to change the mapping.</param> | ||
/// <param name="key">The name of the property.</param> | ||
/// <param name="method">The method to call after the existing mapping is finished.</param> | ||
public static void AppendToMapping<TVirtualView, TViewHandler>(this IPropertyMapper<TVirtualView, TViewHandler> propertyMapper, | ||
public static IPropertyMapper<TVirtualView, TViewHandler> AppendToMapping<TVirtualView, TViewHandler>(this IPropertyMapper<TVirtualView, TViewHandler> propertyMapper, | ||
string key, Action<TViewHandler, TVirtualView> method) | ||
where TVirtualView : IElement where TViewHandler : IElementHandler | ||
{ | ||
propertyMapper.ModifyMapping(key, (handler, view, action) => | ||
return propertyMapper.ModifyMapping(key, (handler, view, action) => | ||
{ | ||
action?.Invoke(handler, view); | ||
method(handler, view); | ||
|
@@ -93,11 +111,11 @@ void newMethod(IElementHandler handler, IElement view) | |
/// <param name="propertyMapper">The property mapper in which to change the mapping.</param> | ||
/// <param name="key">The name of the property.</param> | ||
/// <param name="method">The method to call after the existing mapping is finished.</param> | ||
public static void AppendToMapping<TVirtualView, TViewHandler>(this IPropertyMapper<IElement, IElementHandler> propertyMapper, | ||
public static IPropertyMapper<IElement, IElementHandler> AppendToMapping<TVirtualView, TViewHandler>(this IPropertyMapper<IElement, IElementHandler> propertyMapper, | ||
string key, Action<TViewHandler, TVirtualView> method) | ||
where TVirtualView : IElement where TViewHandler : IElementHandler | ||
{ | ||
propertyMapper.ModifyMapping(key, (handler, view, action) => | ||
return propertyMapper.ModifyMapping(key, (handler, view, action) => | ||
{ | ||
action?.Invoke(handler, view); | ||
|
||
|
@@ -114,11 +132,11 @@ void newMethod(IElementHandler handler, IElement view) | |
/// <param name="propertyMapper">The property mapper in which to change the mapping.</param> | ||
/// <param name="key">The name of the property.</param> | ||
/// <param name="method">The method to call before the existing mapping begins.</param> | ||
public static void PrependToMapping<TVirtualView, TViewHandler>(this IPropertyMapper<TVirtualView, TViewHandler> propertyMapper, | ||
public static IPropertyMapper<TVirtualView, TViewHandler> PrependToMapping<TVirtualView, TViewHandler>(this IPropertyMapper<TVirtualView, TViewHandler> propertyMapper, | ||
string key, Action<TViewHandler, TVirtualView> method) | ||
where TVirtualView : IElement where TViewHandler : IElementHandler | ||
{ | ||
propertyMapper.ModifyMapping(key, (handler, view, action) => | ||
return propertyMapper.ModifyMapping(key, (handler, view, action) => | ||
{ | ||
method(handler, view); | ||
action?.Invoke(handler, view); | ||
|
@@ -133,17 +151,18 @@ void newMethod(IElementHandler handler, IElement view) | |
/// <param name="propertyMapper">The property mapper in which to change the mapping.</param> | ||
/// <param name="key">The name of the property.</param> | ||
/// <param name="method">The method to call before the existing mapping begins.</param> | ||
public static void PrependToMapping<TVirtualView, TViewHandler>(this IPropertyMapper<IElement, IElementHandler> propertyMapper, | ||
public static IPropertyMapper<IElement, IElementHandler> PrependToMapping<TVirtualView, TViewHandler>(this IPropertyMapper<IElement, IElementHandler> propertyMapper, | ||
string key, Action<TViewHandler, TVirtualView> method) | ||
where TVirtualView : IElement where TViewHandler : IElementHandler | ||
{ | ||
propertyMapper.ModifyMapping(key, (handler, view, action) => | ||
return propertyMapper.ModifyMapping(key, (handler, view, action) => | ||
{ | ||
if ((handler is null || handler is TViewHandler) && view is TVirtualView v) | ||
method((TViewHandler)handler!, v); | ||
|
||
action?.Invoke(handler!, view); | ||
}); | ||
} | ||
#pragma warning restore RS0016 // Add public types and members to the declared API | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
There is an alternative that we could do and not have more extension methods: