| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 part of serialization; | 5 part of serialization; |
| 6 | 6 |
| 7 // TODO(alanknight): Figure out how to reasonably separate out the things | 7 // TODO(alanknight): Figure out how to reasonably separate out the things |
| 8 // that require reflection without making the API more awkward. Or if that is | 8 // that require reflection without making the API more awkward. Or if that is |
| 9 // in fact necessary. Maybe the tree-shaking will just remove it if unused. | 9 // in fact necessary. Maybe the tree-shaking will just remove it if unused. |
| 10 | 10 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 * | 90 * |
| 91 * This method lets you designate a function to use to set the value of a | 91 * This method lets you designate a function to use to set the value of a |
| 92 * field. It also makes the contents of that field be treated as essential, | 92 * field. It also makes the contents of that field be treated as essential, |
| 93 * which currently only has meaning if the field is a list. This is done | 93 * which currently only has meaning if the field is a list. This is done |
| 94 * because you might set a list field's special treatment function to add | 94 * because you might set a list field's special treatment function to add |
| 95 * each item individually and that will only work if those objects already | 95 * each item individually and that will only work if those objects already |
| 96 * exist. | 96 * exist. |
| 97 * | 97 * |
| 98 * For example, to serialize a Serialization, we need its rules to be | 98 * For example, to serialize a Serialization, we need its rules to be |
| 99 * individually added rather than just setting the rules field. | 99 * individually added rather than just setting the rules field. |
| 100 * ..addRuleFor(new Serialization()).setFieldWith('rules', | 100 * ..addRuleFor(Serialization).setFieldWith('rules', |
| 101 * (InstanceMirror s, List rules) { | 101 * (InstanceMirror s, List rules) { |
| 102 * rules.forEach((x) => s.reflectee.addRule(x)); | 102 * rules.forEach((x) => s.reflectee.addRule(x)); |
| 103 * Note that the function is passed the owning object as well as the field | 103 * Note that the function is passed the owning object as well as the field |
| 104 * value, but that it is passed as a mirror. | 104 * value, but that it is passed as a mirror. |
| 105 */ | 105 */ |
| 106 void setFieldWith(String fieldName, SetWithFunction setWith) { | 106 void setFieldWith(String fieldName, SetWithFunction setWith) { |
| 107 _fields.addAllByName([fieldName]); | 107 _fields.addAllByName([fieldName]); |
| 108 _NamedField field = _fields.named(_asSymbol(fieldName)); | 108 _NamedField field = _fields.named(_asSymbol(fieldName)); |
| 109 Function setter = (setWith == null) ? field.defaultSetter : setWith; | 109 Function setter = (setWith == null) ? field.defaultSetter : setWith; |
| 110 field.customSetter = setter; | 110 field.customSetter = setter; |
| (...skipping 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 if (value is String) { | 662 if (value is String) { |
| 663 try { | 663 try { |
| 664 return new Symbol(value); | 664 return new Symbol(value); |
| 665 } on ArgumentError { | 665 } on ArgumentError { |
| 666 return null; | 666 return null; |
| 667 }; | 667 }; |
| 668 } else { | 668 } else { |
| 669 return null; | 669 return null; |
| 670 } | 670 } |
| 671 } | 671 } |
| OLD | NEW |