Question

I've been using dart for quite a while now. If I want to implement dynamic getters, setters and functions for objects of a class, I can make use of the noSuchMethod-method. But what if I now want to have such a dynamic getter, setter of method on class layer? In Ruby, for example, if one wants to implement a dynamic class method, one would define the method_missing-method on the class object, like for example:

class Test
    def self.method_missing
        //Do some matching, return result or error
    end
end

How would I achieve this in Dart?

Was it helpful?

Solution

I don't think you can do this in Dart without mirrors/reflection.

I also don't think this is very useful.
You can't call a static method on a 'dynamic' type and therefore you can't mock static methods.

If you need this you should just make it a normal method instead of a static one.

OTHER TIPS

You can just override noSuchMethod as noticed here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top