A
Andrew Ducker
Let's say you have three classes, ClassA, ClassB and ClassC. You'd
like ClassC to descend from ClassA and ClassB (because, for instance,
ClassA is a UserControl and Class C is all of your validation code).
At the moment you can't do it - your code either has to be in a static
helper class or copied into each class manually.
What if, as a way of checking that your code fulfilled an interface,
rather than checking that all the required methods were in place, it
could optionally see if your class could be cast to an implementation
of that interface. Like so:
class ClassC : ClassA , IClassB
{
private ClassB classB = new ClassB();
public static implicit operator IClassB(ClassC classC)
{
return classC.classB;
}
}
(where ClassB implements IClassB).
So that when calls to ClassA methods were needed they'd be passed
straight back up to it. And when calls to ClassB methods were needed it
would do a cast to ClassB and call them that way.
Have I just reinvented something really obvious? Or is there a mistake
in my thinking? Or something else?
Cheers,
Andy
like ClassC to descend from ClassA and ClassB (because, for instance,
ClassA is a UserControl and Class C is all of your validation code).
At the moment you can't do it - your code either has to be in a static
helper class or copied into each class manually.
What if, as a way of checking that your code fulfilled an interface,
rather than checking that all the required methods were in place, it
could optionally see if your class could be cast to an implementation
of that interface. Like so:
class ClassC : ClassA , IClassB
{
private ClassB classB = new ClassB();
public static implicit operator IClassB(ClassC classC)
{
return classC.classB;
}
}
(where ClassB implements IClassB).
So that when calls to ClassA methods were needed they'd be passed
straight back up to it. And when calls to ClassB methods were needed it
would do a cast to ClassB and call them that way.
Have I just reinvented something really obvious? Or is there a mistake
in my thinking? Or something else?
Cheers,
Andy