Test reflection
This commit is contained in:
parent
9b85007072
commit
ec68a78c1d
4 changed files with 6250 additions and 112 deletions
35
experiment/container/example1/bin/main.dart
Normal file
35
experiment/container/example1/bin/main.dart
Normal file
|
@ -0,0 +1,35 @@
|
|||
import 'dart:mirrors';
|
||||
|
||||
void main() {
|
||||
final stopwatch = Stopwatch()..start();
|
||||
|
||||
var reflectedClass = reflect(Shape());
|
||||
|
||||
reflectedClass.invoke(#draw, []);
|
||||
|
||||
//reflectedClass.invoke(Symbol('draw'), []);
|
||||
|
||||
print('Reflection executed in ${stopwatch.elapsed.inMilliseconds} ms');
|
||||
stopwatch.stop();
|
||||
|
||||
printAnnotationValue(String);
|
||||
printAnnotationValue(Shape);
|
||||
}
|
||||
|
||||
class Shape {
|
||||
void draw() => print("Draw Shape");
|
||||
}
|
||||
|
||||
void printAnnotationValue(final Type clazz) {
|
||||
final DeclarationMirror clazzDeclaration = reflectClass(clazz);
|
||||
final ClassMirror someAnnotationMirror = reflectClass(Shape);
|
||||
final annotationInstsanceMirror =
|
||||
clazzDeclaration.metadata.where((d) => d.type == someAnnotationMirror);
|
||||
if (annotationInstsanceMirror.isEmpty) {
|
||||
print('Annotation is not on this class');
|
||||
return;
|
||||
}
|
||||
final someAnnotationInstance =
|
||||
(annotationInstsanceMirror.first.reflectee as Shape);
|
||||
print("${someAnnotationInstance.draw}");
|
||||
}
|
|
@ -20,7 +20,6 @@ void main() async {
|
|||
container.registerSingleton<MyController>(MyController());
|
||||
|
||||
var app = Angel(reflector: reflector);
|
||||
|
||||
var http = AngelHttp(app);
|
||||
|
||||
//await app.mountController<MyController>();
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -35,9 +35,11 @@ dev_dependencies:
|
|||
io: ^1.0.0
|
||||
test: ^1.21.0
|
||||
lints: ^2.0.0
|
||||
# dependency_overrides:
|
||||
# angel3_container:
|
||||
# path: ../container/angel_container
|
||||
dependency_overrides:
|
||||
angel3_container:
|
||||
path: ../../../packages/container/angel_container
|
||||
angel3_container_generator:
|
||||
path: ../../../packages/container/angel_container_generator
|
||||
# angel3_http_exception:
|
||||
# path: ../http_exception
|
||||
# angel3_model:
|
||||
|
|
Loading…
Reference in a new issue