[nem-en] Extension methods (was Re: My thoughts on Nemerle)
Alejandro Serrano
trupill at yahoo.es
Mon Jan 9 17:09:39 CET 2006
I have decided to split the conversation because it was starting to
become confusing.
> > About specifying "this", the only problem I see is that then, on the
> > method code, you have to substitute all references of this with the
> > actual parameters, which I find really painful (and on my point of view,
> > non-sense)
>
> Ah, does it mean that this "extension" parameter is refered to as 'this'? Like:
> module Ex {
> public ListSplit (this x : string) : list [char] {
> List.FromArray (this.Split())
> }
> }
Well, the reason underneath the use of only [Extension] in methods is
that it would not require any modification to the compiler, nor any
macro. Indeed, Microsoft C# Compiler, just translates
public static Method (this string s) { ... }
to
[System.CompilerServices.ExtensionAttribute()]
public static Method (string s) { ... }
Where Extension is a custom attribute already defined in the
System.Query library. We will have to wait until Mono gmcs can compile
the System.Query library, or use my own-compiled one or Microsoft's one.
Because of it, extension parameters can only be used in first place,
because that is what the [Extension] attribute states: hey! I'm really a
method who is extending my first parameter type! Even more, in VB.NET no
actual syntax will be held for extension methods, but appending the
attribute.
[Extension] public static Method (s : string) { ... } is quite well at
my point of view
About how to include extension methods, after all this discussion, I've
seen we cannot be sure that only a class will be used for extension
methods, so I think the best way to go is to allow both "using X" on
classes and namespaces.
______________________________________________
LLama Gratis a cualquier PC del Mundo.
Llamadas a fijos y moviles desde 1 centimo por minuto.
http://es.voice.yahoo.com
More information about the devel-en
mailing list