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.
Implementing extension methods The members of the extension can be methods, getters, setters, operators. Extensions can also have static fields and static helper methods.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With