Re: [Vala] Extension Methods
- From: Uwe Strempel <u strempel googlemail com>
- To: Didier Ptitjes <ptitjes free fr>, vala-list gnome org
- Subject: Re: [Vala] Extension Methods
- Date: Fri, 6 Mar 2009 20:20:50 +0100
Hi,
yes you are right.
C# 3.0 syntac for inner-type declaration is not the best.
This syntax:
public int string.count_words() {
return this.split_set(" .?").length;
}
might be better.
Thanks,
regards
Uwe
2009/3/6 Didier Ptitjes
<ptitjes free fr>
Hello Uwe,
Uwe Strempel wrote:
Hi,
is there any feature like extension methods from c# 3.0 in vala supported.
It would be a cool feature in vala and could allow to write better code.
This mechanism is stolen from aspect oriented programming. This is called inner-type declarations.
namespace ExtensionMethods
{
public static class MyExtensions
{
public static int WordCount(this String str)
{
return str.Split(new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries).Length;
}
} }
This would technically be possible. (And would be pretty cool to have as lots of glib libraries provide functions for types defined in other libraries) However I doubt this is in the 1.0 feature plan.
Also that above syntax is ugly. Having static keywords all the way hides the fact this becomes an instance method. I would rather see a syntax closer to the one of aspectJ :
public int string.count_words() {
return this.split_set(" .?").length;
}
thanks,
regards
uwe
Best reagards, Didier.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]