I have a class sealed,
sealed
public sealed class A { public string AName {get;set;} }
and someone can write an extension method for it like this:
public static class Extensions { public static void ExtensionMethodForA (this A a) { Console.WriteLine("A Extension method!"); } }
The question is how do you prevent this?
No. You can not. And you should not want this.
Instance methods always prefer extension methods, so it should not be a conflict. Other than that, they are just syntax / convenience. Do not try to make life uncomfortable for callers.
" ". ; . , , .
, .
. , , .
'this' , , . . .
- , , .