Re: [Vala] [RFC] Extension methods (Re: maemo5 hildon input mode)



Jan-Jaap van der Geer píše v St 10. 02. 2010 v 02:34 -0800:
Jan Hudec <bulb ucw cz> wrote:
This looks like another use-case for extension methods in a day.

I'd like to see them as well.
 

It might be useful, in some cases. It should be noted that extension
methods can only access class' public members.

namespace Moo {
    bool less_or_equal(IComparable this lhs, IComparable rhs) {
        return !rhs.less_than(lhs);
    }
}

The C# syntax is actually a little bit different: You need to swap the type and "this":

namespace Moo {
    bool less_or_equal(this IComparable lhs, IComparable rhs) {
        return !rhs.less_than(lhs);
    }
}

I feel like we should follow C# regarding that. In C# the method must be static and must be placed in a 
static class as well.


I disagree with that. The C# way feels like an ugly hack to me.
How about something like this:

public class extension Gtk.Entry {
        public void some_additional_stuff () {
                // do something
        }
}

or similarly:

public interface extension IComparable {
        public bool less_or_equal (IComparable rhs) {
                return !rhs.less_than (this);
        }
}

Attachment: signature.asc
Description: Toto je digitálně podepsaná část zprávy



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]