The compiler does not need to know that the class is extension, nothing requires this, and there is actually no extension class (yet), there are static classes that have static methods that are extension. One reason for recommending that you write something in the name to indicate that the class has the purpose of extending another (s) class(s). Even the static class need not only have extension methods. The name indicates nothing, including I only use Ext
at the end of the name because it’s enough for me to identify who it’s about.
The extension method is defined (up to the current version that I write this) by a keyword this
that goes before the first declared parameter. This syntactic difference is enough for the compiler to know.
In the future there must be another way to express various extensions, not only methods, and may be by a syntax that demonstrates this more clearly and will have something like an extension class, but not a class. Classes are overvalued.
The static class itself is kind of weird. C# tried to copy a little the idea of Java that was in fashion and that sold the idea that everything should be in classes, after at that time only the technology that was sold as object oriented was successful, And then an obsession started, so it’s not over yet, and it ruins a lot of people’s heads, and it makes horrible codes be written to look like they’re OOP, even when the ideal is that they’re not. Now they’re more prepared to have things that aren’t classes, because a class doesn’t always make sense. Call it a module or something, you don’t have to invent something that’s not a class just to pretend it’s OOP. Actually the problem is even bigger, was what we could summarize in a paragraph.
the operator
this
who does that job. https://docs.microsoft.com/pt-br/dotnet/csharp/programming-guide/classes-and-structs/extension-methods– Rovann Linhalis
related: https://answall.com/questions/136913/para-que-usar-m%C3%A9todos-de-extens%C3%A3o-do-c
– novic
missing in the example the
static
also in the methods– novic