@@ -30,7 +30,7 @@ your pubspec.yaml file.
30302 . Register a [ Decoder] [ Decoder ] object for each * user defined*
3131data-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
4646is shown in section [ Reading an Enumeration] ( #reading-an-enumeration ) .
4747
48484 . 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
56625 . Use the constant values to generate the source-code and complete the building
5763process.
@@ -61,11 +67,10 @@ process.
6167The extension [ ` Reader ` ] [ Reader ] provides a systematic method of
6268retrieving constants of
6369arbitrary 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 ] .
6974The example below demonstrates how to create a custom decoder for the
7075sample class ` Annotation ` and register an instance of the decoder with
7176the 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