I'm trying to add support for adding constraints to function parameters and returns for the
constrain library.
For objects I look up and cache the constraint metadata based on the object's Type. For functions I'm struggling to find what to key the cached meta data on.
I want to support standalone functions like
String bar(int blah, [String boo = 'abc']) => '';
and methods on classes like
class Foo {
String bar(int blah, [String boo = 'abc']) => '';
}
So the idea is to allow things like
@NotNull String bar(@Min(10) int blah, [@Pattern('[\w]+') String boo = 'abc']) => '';
and methods on classes like
class Foo {
@NotNull String bar(@Min(10) int blah, [@Pattern('[\w]+') String boo = 'abc']) => '';
}
So I need a unique key for these functions / methods such that:
- it is always the same for the same function
- it is always the same for the same method of a class. i.e. across all instances of that class / subclasses etc
- functions with the same signature (runtimeType) are seen as distinct i.e. don't match. e.g. the function bar does not match the method bar on the class Foo
The only thing that I have found that seems to fit this bill is MethodMirror.
However, MethodMirror is part of the mirror library which I plan to move away from at some point and use code generation instead. For objects I can use Type (via o.runtimeType). Is there something similar I can use here that I am missing?
A