Jon Slaughter said:
You are right, it becomes impossible to detect where they were
declared.
Not when you've got code *using* them.
It would be interesting to see how a reflector tool will interprete
them. For example an extension method to the String system class (that
is declared as sealed)
Has anybody test it?
Reflector is dealing with code which is already calling the extension
methods. That's really easy to detect, because it knows exactly the
method being called and can check for the extension attribute.
It won't know whether it was called *as* an extension method or not - I
could write:
new List<string>().Count();
or
Enumerable.Count(new List<string>())
and the compiled code will be the same - but it knows exactly which
method was called and that it *could* have been written as an extension
method.
AFAIK they can't unless they use some different method... these extensions
just don't show up using GetMethods or even GetMembers. (Unless theres some
combo of flags)
That's checking something very different - what extensions are
available on a particular type. That depends on which namespaces and
assemblies are being considered; without a "using System.Linq"
directive, IEnumerable<T> doesn't have a Count() member, for instance.
Of course, you could write your own extension methods for Type which
allowed GetMethods to also take a list of namespaces and assemblies to
search for extension methods
My guess is they will just show the extension as a normal method call
instead as this seems to be what the compiler does internally anyways.
(although maybe the reflector could guess that they are extensions)
That depends on what you mean by "as a normal method call". The
compiled code treats them as just static method calls - because that's
what they are.