Announcement

Collapse
No announcement yet.

How do I make extension methods emit simple code.

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • txdv
    started a topic How do I make extension methods emit simple code.

    How do I make extension methods emit simple code.

    Hey guys, I am using an addon, for bootstrap which basically adds a method .datetimepicker to every jQuery object so you can make a datepicker out of it.

    Now the problem that I face that I don't know how to express that in Bridge.net. I tried something like this:

    [Ignore]
    public static class DatePickerExtensions
    {
        [Name("datetimepicker")]
        public static DatePicker DateTimePicker(this jQuery jQuery, DatePickerOptions options)
        {
            return null;
        }
    }
    But it still generates code like:

    Web.DatePickerExtensions.datetimepicker(obj, { defaultDate: obj.attr("value"), format: "YYYY.MM.DD" });
    What I really need is

    obj.datetimepicker({ defaultDate: obj.attr("value"), format: "YYYY.MM.DD" });
    Is there anyway to achieve this?

  • geoffrey.mcgill
    replied
    The [NativeMethod] Attribute was added to the master-branch, although we have determined this feature is not required and have removed.

    The original code sample will work as expected now.

    Example (.cs)

    [Ignore]
    public static class DatePickerExtensions
    {
        [Name("datetimepicker")]
        public static DatePicker DateTimePicker(this jQuery jQuery, DatePickerOptions options)
        {
            return null;
        }
    }
    Example (emitted .js)

    obj.datetimepicker({ defaultDate: obj.attr("value"), format: "YYYY.MM.DD" });
    Hope this helps.

    Leave a comment:


  • Daniil
    replied
    Thank you. Just in my experience when I needed an extension method, I needed this behavior by default rather than defining [Template] for each method. I like your idea taking [Ignore] into account.

    NativeMethod can be apply to class also
    Great.

    Leave a comment:


  • Vladimir
    replied
    I don't think that it should be by default. Or it can be by default for static class which is marked as Ignore (mostly, Ignore means that class already is implemented in javascript). I will think about it

    NativeMethod can be apply to class also

    Leave a comment:


  • Daniil
    replied
    In 1.9 release we will add NativeMethod attribute which will mark extensions method and points the translator that method belongs the scope in javascript
    Vladimir, should it be the behavior by default, shouldn't?

    In any way, it would be great to have a class level attribute as well.

    Leave a comment:


  • Vladimir
    replied
    In 1.9 release we will add NativeMethod attribute which will mark extensions method and points the translator that method belongs the scope in javascript

    Leave a comment:


  • txdv
    replied
    Works perfectly, thanks!

    Leave a comment:


  • Vladimir
    replied
    Hi
    Try to set the following Template attribute to DateTimePicker method
    [Template("{this}.datetimepicker({options})")]
    Name attribute can be removed in this case

    Leave a comment:

Working...
X