I have an extension method in what I will call HelperAssembly , which looks something like this:
public static class HelperClass { public static void MyHelperMethod(this SomeClass some, OtherClass other) {
I have an assembly, which I will call CallerAssembly , which has a reference to HelperAssembly .
My HelperAssembly has a link to both OtherAssembly1 and OtherAssembly2 .
SomeClass and OtherClass are defined in ReferenceAssembly . HelperAssembly and CallerAssembly have a reference to ReferenceAssembly .
Everything is fine when I call my method from CallerAssembly as follows:
HelperClass.MyHelperMethod(some, other);
However, I get build errors when I call it (as an extension method):
some.MyHelperMethod(other);
Errors say that CallerAssembly needs to be referenced by OtherAssembly1 and OtherAssembly2 .
I'm confused. I thought the syntax of the extension method was just syntactic sugar, but didn't really change the way things were compiled.
I do not want to add the links that it offers, so I will not make the call as an extension method. But I would like to understand what the difference is.
Why does calling a method directly build, but calling it as an extension method fails to build?
Vaccano
source share