Mif*_*Fox 9 c# intellisense extension-methods
我目前在System.Windows.Forms.Control上有一个扩展方法,如下所示:
public static void ExampleMethod(this Control ctrl){ /* ... */ }
Run Code Online (Sandbox Code Playgroud)
但是,此方法不会出现在从Control派生的类中,例如PictureBox.我是否可以创建一个不仅出现在Control中的扩展方法,而且对于从Control派生的类,而不必进行显式转换?
请注意,如果您从类中的属性调用扩展方法,该类继承自应用了扩展方法的基类,则必须为扩展方法添加后缀this
例如
public int Value
{
get => this.GetValue<int>(ValueProperty);
set => SetValue(ValueProperty, value);
}
Run Code Online (Sandbox Code Playgroud)
GetValue我的扩展方法在哪里应用于基类。