Extension methods are just changing compile time:
x.GetValueAsBoolean()
to
Extensions.GetValueAsBoolean(x)
What all this means is translating what looks like an instance method call into a static method call.
If you do not have performance problems with the static method, then using this extension method will not lead to any new problems.
EDIT: IL as requested ...
Taking this sample:
using System; public static class Extensions { public static void Dump(this string x) { Console.WriteLine(x); } } class Test { static void Extension() { "test".Dump(); } static void Normal() { Extensions.Dump("test"); } }
Here is the IL for Extension and Normal :
.method private hidebysig static void Extension() cil managed {
As you can see, they are exactly the same.
Jon Skeet Jun 17 '09 at 12:02 2009-06-17 12:02
source share