2021-05-14 10:34:09 +00:00
|
|
|
import 'package:angel3_container/angel3_container.dart';
|
2016-09-15 19:53:01 +00:00
|
|
|
|
2019-05-02 22:48:31 +00:00
|
|
|
final RegExp straySlashes = RegExp(r'(^/+)|(/+$)');
|
2017-11-28 18:14:50 +00:00
|
|
|
|
2021-03-20 08:11:18 +00:00
|
|
|
T? matchingAnnotation<T>(List<ReflectedInstance> metadata) {
|
2021-07-08 02:42:40 +00:00
|
|
|
for (var metaDatum in metadata) {
|
2018-08-21 18:50:43 +00:00
|
|
|
if (metaDatum.type.reflectedType == T) {
|
2021-03-20 08:11:18 +00:00
|
|
|
return metaDatum.reflectee as T?;
|
2016-09-15 19:53:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-21 18:50:43 +00:00
|
|
|
|
2016-09-15 19:53:01 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-03-20 08:11:18 +00:00
|
|
|
T? getAnnotation<T>(obj, Reflector? reflector) {
|
2018-08-21 02:44:32 +00:00
|
|
|
if (reflector == null) {
|
|
|
|
return null;
|
2016-09-15 19:53:01 +00:00
|
|
|
} else {
|
2018-08-21 02:44:32 +00:00
|
|
|
if (obj is Function) {
|
2021-03-20 08:11:18 +00:00
|
|
|
var methodMirror = reflector.reflectFunction(obj)!;
|
2019-04-08 19:53:07 +00:00
|
|
|
return matchingAnnotation<T>(methodMirror.annotations);
|
2018-08-21 02:44:32 +00:00
|
|
|
} else {
|
2021-05-15 17:58:51 +00:00
|
|
|
var classMirror = reflector.reflectClass(obj.runtimeType)!;
|
2019-04-08 19:53:07 +00:00
|
|
|
return matchingAnnotation<T>(classMirror.annotations);
|
2018-08-21 02:44:32 +00:00
|
|
|
}
|
2016-09-15 19:53:01 +00:00
|
|
|
}
|
2017-09-22 14:03:23 +00:00
|
|
|
}
|