Skip to content

Commit ad8f1f3

Browse files
committed
Amended docs.
1 parent 2493b68 commit ad8f1f3

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.5.2
2+
- Removed libraries `test_methods.dart` and `test_utils.dart`.
3+
- Amended documentation.
4+
15
## 0.5.1
26
- Added the following built-in types that are supported without the
37
need to register a decoder:

README.md

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ your pubspec.yaml file.
3030
2. Register a [Decoder][Decoder] object for each *user defined*
3131
data-type `U` that is going to be read
3232
(see section [Custom Decoders](#custom-decoders)). </br>
33-
Note: The following type are supported out-of-the-box and do *not* require a decoder:
33+
Note: The following types are supported out-of-the-box and do *not* require a decoder:
3434
* `bool`, `double`, `int`, `num`,`String`, `Type`, `Symbol`,
3535
* `List<bool>`, `List<double>`, `List<int>`, `List<num>`,
3636
`List<String>`,`List<Symbol>`,`List<Type>`,
@@ -46,12 +46,18 @@ using the method [`computeConstantValue()`][computeConstantValue()]. An exmple
4646
is shown in section [Reading an Enumeration](#reading-an-enumeration).
4747

4848
4. Read the compile-time constant values using the extension method: [`read<T>`][read]. <br/>
49-
To read a constant representing a *collection* of a *user-defined* type `U`
49+
50+
* To read a constant representing a *collection* of a *user-defined* type `U`
5051
use the convenience methods [`readList<U>`][readList],
5152
[`readSet<U>`][readSet], [`readMap<K,U>`][readMap], and [`readIterator<U>`][readIterator].
52-
On first use, these methods register a decoder making the types:
53-
`List<U>`, `Set<U>`, `Map<K,U>`, `Iterable<U>` readable with [`read<U>`][read].
53+
These methods register a suitable decoder and call [`read`][read].
54+
For example calling [`readList<U>(obj)`][readList], registers the decoder
55+
`ListDecoder<U>()` and calls `read<List<U>>(obj)`.
5456

57+
* If the compile-time constant represents a class which defines instance
58+
variables, one may read a specific instance variable by specifying
59+
the parameter `fieldName`. For more info see section
60+
[Custom Decoders](#custom-decoders).
5561

5662
5. Use the constant values to generate the source-code and complete the building
5763
process.
@@ -61,11 +67,10 @@ process.
6167
The extension [`Reader`][Reader] provides a systematic method of
6268
retrieving constants of
6369
arbitrary data-types by allowing users to register [`Decoder`][Decoder] objects.
64-
To create a custom decoder extend [`Decoder<T>`][Decoder] and override the
65-
the method `T read<T>(DartObject obj)`. This method
66-
attempts to read a variable of type `T` from the compile-time constant
67-
`obj` and returns the result.
6870

71+
72+
To create a custom decoder extend [`Decoder<T>`][Decoder] and override the
73+
the method [`T read(DartObject obj)`][Decoder.read].
6974
The example below demonstrates how to create a custom decoder for the
7075
sample class `Annotation` and register an instance of the decoder with
7176
the extension [`Reader`][Reader].
@@ -87,7 +92,10 @@ class AnnotationDecoder extends Decoder<Annotation> {
8792
8893
@override
8994
Annotation read(DartObject obj) {
95+
// Read instance variable 'id'.
9096
final id = obj.read<int>(fieldName: 'id');
97+
98+
// Read instance variable 'names'.
9199
final names = obj.read<Set<String>>(fieldName: 'names');
92100
return A(id: id, names: names);
93101
}
@@ -273,6 +281,8 @@ Please file feature requests and bugs at the [issue tracker].
273281

274282
[read]: https://pub.dev/documentation/generic_reader/latest/generic_reader/Reader/read.html
275283

284+
[Decoder.read]: https://pub.dev/documentation/generic_reader/latest/generic_reader/Decoder/read.html
285+
276286
[readIterator]: https://pub.dev/documentation/generic_reader/latest/generic_reader/Reader/readIterator.html
277287

278288
[readList]: https://pub.dev/documentation/generic_reader/latest/generic_reader/Reader/readList.html

0 commit comments

Comments
 (0)