For my own personal edification–is there any way to do this? I’m implementing an Imageable class that provides a ToWmf() function that outputs the WPF object to a vector graphic. But this only makes sense for WPF Visual types, and so one of the components of the imaging operation requires a parameter with type Visual, which I would intend to be this.
I’ve found all kinds of examples of C# parameter constraints but no examples of constraining the inheriting class type. For the time being I’m using a static ImagingUtil.ToWmf() class, but is this just a flat-out No answer or is there another way?
The question implies that the
Imageableobject would also be aVisualat the same time (otherwise how are you going to passthisto something that needs aVisual?).This is not possible unless one of the two types inherits from the other, and since
Visualis not under your control thenImageablemust be a descendant ofVisual. In which case there is no problem at all.In all likelihood what you want to be doing is defining an
IImageableinterface and then implementing an extension method that looks like this:This way any (and only a) user-defined class that derives from
Visualand at the same time implementsIImageablecan be processed byToWmf.