C
C#5mo ago
Alizer

advanced inheritance in arguments

I need help with C# inheritance, basically I have this function
private void SetTopView<T>(T child) where T : FrameworkElement, IPopup
{
LayerAboveContent.Children.Clear();

child.CloseTriggered += (sender, args) => { LayerAboveContent.Children.Remove(sender as FrameworkElement); };

child.ReplaceTriggered += (sender, element) =>
{
SetTopView(element); // this gets an error! but I know `element` here derrives IPopup too!
};

LayerAboveContent.Children.Add(child);
}
private void SetTopView<T>(T child) where T : FrameworkElement, IPopup
{
LayerAboveContent.Children.Clear();

child.CloseTriggered += (sender, args) => { LayerAboveContent.Children.Remove(sender as FrameworkElement); };

child.ReplaceTriggered += (sender, element) =>
{
SetTopView(element); // this gets an error! but I know `element` here derrives IPopup too!
};

LayerAboveContent.Children.Add(child);
}
now on the code at child.ReplaceTriggered += (sender, element) => my problem is that element here is a FrameworkElement but I know fully well that this object inherits IPopup in my own code because all instance of element I pass through here inherits IPopup, now, my SetTopView function here accepts T where T should inherit both FrameworkElement and IPopUp, how do I make the compiler accept element here in the code to also have derrived from IPopup?
No description
2 Replies
Alizer
Alizer5mo ago
in short I want to do the following
No description
Moods
Moods5mo ago
How do you know it implements IPopUp? is element of a type derived from FrameworkElement that also implements that interface?