I have the following method
private void PushToMainWindow(UserControl child) // where child is IMainWindowPlugin
{
_navigationStack.Push((IMainWindowPlugin)child);
...
// Here I do stuff that makes use of the child as a usercontrol
child.Width = 500;
child.Margin = new Thickness(0,0,0,0);
...
}
What I would like to do is inform the compiler that I'll only be accepting UserControl objects that also implement the IMainWindowPlugin interface.
I know I can do a if statement and throw or cast and check for null, but those are both run-time solutions, and I'm looking for a way to tell the developer up front that there is a restriction on the type of UserControl he can add. Is there a way to say this in c# ?
UPDATE: Added more code to show that the usercontrol is used as a usercontrol, so I can't just pass the child as the interface.