SplitterPanel
はsealed
クラスですが、Panel
そうではありません。
型から派生することはできませんsealed
。
ドキュメント:
シール クラスは継承できません。シール クラスを基底クラスとして使用するのはエラーです。クラスの継承を防ぐには、クラス宣言で seal 修飾子を使用します。
クラスの機能を拡張したい場合sealed
、[IMO] の最善の方法は拡張メソッドを作成することです。例えば:
public static class SplitterPanelExtensions {
public static void MyAdvancedMethod(this SplitterPanel splitterPanel) {
/*
* Check if splitterPanel is null and throw ArgumentNullException.
* because extension methods are called via "call" IL instruction.
*/
//Implementation.
}
//Other extension methods...
}
もう 1 つの方法は、sealed クラスのインスタンスを保持するクラスを作成することです。ラップしているクラスのインターフェースの一部を隠したい場合は、これがより良い選択です。例えば:
public class SplitterPanelWrapper {
private readonly SplitterPanel m_SplitterPanel;
public SplitterPanelWrapper(SplitterPanel splitterPanel) {
m_SplitterPanel = splitterPanel;
}
//Other implementation.
}