Extension methods are a language feature, that allows you to extend the behavior of any class or interface. Basically this is just syntactic sugar to simplify the call to a static method and make it look like a call to an instance method.
In the declaration of the extension method note the this
before IJSRuntime js
. This means the method extends the IJSRuntime
type:
public static async ValueTask<bool> Confirm(this IJSRuntime js, string message)
Under the hood the call to
js.Confirm("text");
gets translated to
IJSRuntimeExtensionMethodsInstance.Confirm(js, "text");
and you could also call the method like this!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…