The first parameter to a C# extension method is the instance that the extension method was called on. I have adopted an idiom, without seeing it elsewhere, of calling that variable ‘self’. I would not be surprised at all if others are using that as well. Here’s an example:
public static void Print(this string self) { if(self != null) Console.WriteLine(self); }
However, I’m starting to see others name that parameter ‘@this’, as follows:
public static void Print(this string @this) { if(@this != null) Console.WriteLine(@this); }
And as a 3rd option, some prefer no idiom at all, saying that ‘self’ and ‘@this’ don’t give any information. I think we all agree that sometimes there is a clear, meaningful name for the parameter, specific to its purpose, which is better than ‘self’ or ‘@this’. Some go further and say you can always come up with a more valuable name. So this is another valid point of view.
What other idioms have you seen? What idiom do you prefer, and why?
I have seen obj and val used. I do not like @this. We should try to avoid using keywords. I have never seen self but I like it.