How to call a base class's base class method

  • Thread starter Thread starter Bill Menees
  • Start date Start date
B

Bill Menees

I've got a RichTextBoxEx inherited from RichTextBox, and I want to overload
the TextLength property to use TextBoxBase's implementation of TextLength.
But since TextBoxBase isn't my immediate base class, I don't know how to
call its TextLength property. Any ideas?

public override int TextLength
{
get
{
return base.TextLength; //Uses RichTextBox.TextLength, which I
don't want.
return TextBoxBase.TextLength; //Doesn't compile.
return base.base.TextLength; //Doesn't compile.
}
}

Any calls I make through a cast to my this pointer should just come right
back into my implementation rather than going to a base implementation since
TextLength is virtual. So is there a way to do this in C# without using
Reflection?
 
Bill Menees said:
I've got a RichTextBoxEx inherited from RichTextBox, and I want to overload
the TextLength property to use TextBoxBase's implementation of TextLength.
But since TextBoxBase isn't my immediate base class, I don't know how to
call its TextLength property. Any ideas?

You can't.
Any calls I make through a cast to my this pointer should just come right
back into my implementation rather than going to a base implementation since
TextLength is virtual. So is there a way to do this in C# without using
Reflection?

Even with reflection, you won't be able to do it, as far as I know. You
usually *shouldn't* do this, either - if the base class wishes to make
its ancestor's implementations available in some way, it should expose
it somehow (eg with a method or property which calls its base
method/property). If the base class *doesn't* wish to make its
ancestor's implementations available, that's its choice.
 
Back
Top