P
Paul E Collins
I am writing a class that inherits from TextBox. My class,
UndoTextBox, extends the standard control by enabling multi-level undo
and redo operations.
Annoyingly, some of the affected properties and methods (such as
CanUndo and Clear) are not virtual and therefore cannot be overridden.
I have hacked around this by declaring 'new' methods, e.g.
public new bool CanUndo
{
get { return m_undoStack.CanUndo; }
}
Since "a constant, field, property, or type introduced in a class or
struct hides all base class members with the same name", I assume that
the correct CanUndo will be called even if, say, the object in
question has been cast to TextBoxBase.
However, this still feels like a (necessary) hack. Are there any other
repercussions I should take into account when using 'new' like this?
P.
UndoTextBox, extends the standard control by enabling multi-level undo
and redo operations.
Annoyingly, some of the affected properties and methods (such as
CanUndo and Clear) are not virtual and therefore cannot be overridden.
I have hacked around this by declaring 'new' methods, e.g.
public new bool CanUndo
{
get { return m_undoStack.CanUndo; }
}
Since "a constant, field, property, or type introduced in a class or
struct hides all base class members with the same name", I assume that
the correct CanUndo will be called even if, say, the object in
question has been cast to TextBoxBase.
However, this still feels like a (necessary) hack. Are there any other
repercussions I should take into account when using 'new' like this?
P.