Replies: 7 comments
-
I won't say impossible. But you may not want to.
My concern is the fact that if the frawework is done correctly you should not have this problem. In your exemple both inherit from "RoutedEventArgs" who have Handle property. |
Beta Was this translation helpful? Give feedback.
-
RoutedEventArgs is sealed class from the .Net framework so it cannot be inherited. Well I meant an elegant solution, obviously you could put dynamics everywhere as you suggest, but what I was proposing is a better way to do it as we have the "is" keyword. |
Beta Was this translation helpful? Give feedback.
-
You are asking for some form of duck typing. Compiler can generate proxy class to emulate "declared later" or "structural" interface and substitute this proxy for original object where structural or "declare later" interface is needed as argument. Performance of reflection is bad and there is naturally no way to make it comparable with strongly-typed invokes. So reflection is the last hope when anything else fail. |
Beta Was this translation helpful? Give feedback.
-
Shapes would provide an efficient solution. #164 |
Beta Was this translation helpful? Give feedback.
-
How using the shapes solution would look like? |
Beta Was this translation helpful? Give feedback.
-
The proposal discussion is in the early stages so the syntax will very likely change but this is what it might look like: public shape SHandleable {
bool Handled { get; set; }
}
private async void RightTapped(object sender, RightTappedRoutedEventArgs e) => Remove(e);
private async void Holding(object sender, RightTappedRoutedEventArgs e) => Remove(e);
private async void Remove<T>(T args) where T : SHandleable
{
args.Handled = true;
await Logic();
} You can think of a "shape" as being very similar to an interface except that they support "duck-typing" in that the class doesn't actually have to implement the shape as long as it exposes the compatible members. The compiler will also allow extension methods (and properties, that's a part of the same spec) to be considered. |
Beta Was this translation helpful? Give feedback.
-
I understand, looks good. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently the framework allows you to:
if( obj is Grid grid) grid.Width = 123;
I have some code with events that looks like:
Because TappedRoutedEventArgs and HoldignRoutedEventArgs have the same name property "Handled" but is not inherited it is impossible to reuse code in that case. It would be nice to have something like:
Beta Was this translation helpful? Give feedback.
All reactions