I’ve got a base class called Graph and an interface called IDataTip.
I’ve got a number of classes that implement both of these, for example:
class TreeGraph : Graph, IDataTip
{
//interface implementation
}
I was wondering if there was a way to declare a member of another class such that the type of the member requires classes that match both the abstract class and the interface?
For example, in the following class:
class GraphExporter
{
public Object GraphWithDataTip {set; get;}
}
I would like to be able to replace the Object type with something that indicates that GraphWithDataTip should be inherit from Graph and implement IDataTip. Is there any way to do this? Or if not, could somebody recommend a more sensible design?
Thanks in advance!
It sounds as though you want either:
abstract class thing : Graph, IDataTip) to be used for your parametervoid MyMethod<T>(T thing) where T : Graph, IDataTipAlternatively, you could cast the parameter within your method and throw an exception if it’s not suitable, but this would be a runtime-only check.