Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Unified Diff: code/ch03/mirrors.dart

Issue 103483002: add back dart:mirrors content, remove dart:isolate, misc. tweaks/updates (Closed) Base URL: https://github.com/dart-lang/dart-up-and-running-book.git@master
Patch Set: move a misplaced comment Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ch03.xml ('K') | « ch03.xml ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: code/ch03/mirrors.dart
diff --git a/code/ch03/mirrors.dart b/code/ch03/mirrors.dart
index f762a031c3511788fba52e8c085753ca025eee5c..01c99ac005e257a2280dfac9cec2c1dd0f4cd47b 100644
--- a/code/ch03/mirrors.dart
+++ b/code/ch03/mirrors.dart
@@ -8,7 +8,6 @@ class Person {
int age;
Person(this.firstName, this.lastName, this.age);
- Person.noFirstName(this.lastName, this.age);
String get fullName => '$firstName $lastName';
@@ -41,6 +40,7 @@ main() {
reflectFromInstance() {
var person = new Person('Bob', 'Smith', 33);
ClassMirror mirror = reflectClass(person.runtimeType);
+ assert('Person' == MirrorSystem.getName(mirror.simpleName));
}
showConstructors(ClassMirror mirror) {
@@ -69,6 +69,19 @@ reflectOnInstance() {
var p = new Person('Bob', 'Smith', 42);
InstanceMirror mirror = reflect(p);
+ // Get the object that the mirror reflects.
var person = mirror.reflectee;
assert(identical(p, person));
+
+ // Invoke a method on the object.
+ mirror.invoke(#greet, ['Shailen']);
+
+ // Get the value of a property.
+ var fullName = mirror.getField(#fullName).reflectee;
+ assert(fullName == 'Bob Smith');
+
+ // Set the value of a property.
+ mirror.setField(#firstName, 'Mary');
+ assert(p.firstName == 'Mary');
+ assert(p.fullName == 'Mary Smith');
}
« ch03.xml ('K') | « ch03.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698