Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Dart have extension methods like c#?

Can you can make extension methods in dart? like you can in C# e.g.:

void swap(this CssClassSet ccs, String oldClass, String newClass)
{
    ccs.remove(oldClass);
    ccs.add(newClass);
}

is this sort of thing possible with Dart? I would like to extend CssClassSet to have a swap(String oldClass, String newClass) method.

like image 797
Daniel Robinson Avatar asked Jul 26 '13 12:07

Daniel Robinson


People also ask

What are the extension methods in DART?

Implementing extension methods The members of the extension can be methods, getters, setters, operators. Extensions can also have static fields and static helper methods.

What is extension method function?

Extension methods enable you to "add" methods to existing types without creating a new derived type, recompiling, or otherwise modifying the original type. Extension methods are static methods, but they're called as if they were instance methods on the extended type.


1 Answers

6 years later and extension functions are finally on the horizon: https://github.com/dart-lang/language/issues/41#issuecomment-539251446

They will be included in dart 2.6

like image 103
lhk Avatar answered Sep 22 '22 11:09

lhk