No overhead. This is just a static method with different syntax. The generated IL is a common call.
In other words, the overhead for your extension method is exactly the same for
writer.WriteElementString(name, data);
as if you just called
XmlWriterExtensions.WriteElementString(writer, name, data);
... because the generated IL will be exactly the same.
In terms of productivity, βover several thousand times per secondβ is nothing. The overhead for having an extra stack level will be completely negligible at that level ... even if the method is not included, which, in my opinion, is very likely in this case.
However, the normal rule of execution applies: all guesses until you have measured. Or at least the actual blow in this case is a hunch; "extension methods are just ordinary methods with syntactic sugar in the compiler" - this is not speculation.
Jon Skeet Sep 18 '09 at 6:33 2009-09-18 06:33
source share