platform/packages/framework/lib/src/util.dart
2021-07-08 10:42:40 +08:00

27 lines
725 B
Dart

import 'package:angel3_container/angel3_container.dart';
final RegExp straySlashes = RegExp(r'(^/+)|(/+$)');
T? matchingAnnotation<T>(List<ReflectedInstance> metadata) {
for (var metaDatum in metadata) {
if (metaDatum.type.reflectedType == T) {
return metaDatum.reflectee as T?;
}
}
return null;
}
T? getAnnotation<T>(obj, Reflector? reflector) {
if (reflector == null) {
return null;
} else {
if (obj is Function) {
var methodMirror = reflector.reflectFunction(obj)!;
return matchingAnnotation<T>(methodMirror.annotations);
} else {
var classMirror = reflector.reflectClass(obj.runtimeType)!;
return matchingAnnotation<T>(classMirror.annotations);
}
}
}