I needed to extend all the Blazor components with a couple of convenient methods (doesn't matter why, just some project-specific stuff).
I'm not sure if it is the only way to do it in Blazor, but I decided to use the good old extension methods:
public static class ComponentBaseExtensions
{
public static string MyMethod(this ComponentBase component, ...)
{
...
}
}
Everything went fine, except one annoying issue: these extension methods are only awailable if I call them through this, i.e. that code is valid:
<div class="@this.MyMethod()"></div>
and this one isn't:
<div class="@MyMethod()"></div>
So, the question is: why it behaves like that and how to get rid of it (if possible) to make the razor templates cleaner?