C#C
C#2y 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);
    }

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?
image.png
Was this page helpful?