@@ -10,8 +10,8 @@ and methods during the build process.
1010
1111Source code generation relies heavily on * constants* known at compile time,
1212represented by a [ ` DartObject ` ] [ DartObject ] .
13- For built-in types, [ ` DartObject ` ] [ DartObject ] has methods that
14- allow reading the underlying constant object to obtain a runtime object.
13+ For core types, [ ` DartObject ` ] [ DartObject ] has methods that
14+ allow reading the underlying constant object to create a runtime object.
1515
1616The package [ ` generic_reader ` ] [ generic_reader ] includes an extention on
1717[ ` DartObject ` ] [ DartObject ] that * simplifies* reading constants of
@@ -29,16 +29,33 @@ your pubspec.yaml file.
2929
30302 . Register a [ Decoder] [ Decoder ] object for each * user defined*
3131data-type ` T ` that is going to be read.
32- Note: The built-in types ` bool ` , ` double ` , ` int ` , ` num ` ,` String ` , ` Type ` , ` Symbol `
33- do ** not** require a decoder.
32+ Note: The following type are supported out-of-the-box and do * not* require a decoder:
33+ * ` bool ` , ` double ` , ` int ` , ` num ` ,` String ` , ` Type ` , ` Symbol ` ,
34+ * ` List<bool> ` , ` List<double> ` , ` List<int> ` , ` List<num> ` ,
35+ ` List<String> ` ,` List<Symbol ` ,` List<Type ` ,
36+ * ` Set<bool ` , ` Set<double ` , ` Set<int ` , ` Set<num ` , ` Set<String ` , ` Set<Symbol ` ,
37+ ` Set<Type ` ,
38+ * ` Iterable<bool ` ,` Iterable<double ` ,` Iterable<int ` ,` Iterable<num ` ,` Iterable<String ` ,
39+ ` Iterable<Symbol ` ,` Iterable<Type ` .
3440
35413 . Use Dart's static [ ` analyzer ` ] [ analyzer ] to read a library, get
3642the relevant [ ` VariableElement ` ] [ VariableElement ] , and calculate the constant
3743expression represented by a [ ` DartObject ` ] [ DartObject ] using the method [ ` computeConstantValue() ` ] [ computeConstantValue() ] .
3844
39- 4 . Read the compile-time constant values using the extension methods [ ` read<T> ` ] [ read ] ,
40- [ ` readList<T> ` ] [ readList ] , [ ` readIterator<T> ` ] [ readIterator ]
41- [ ` readSet<T> ` ] [ readSet ] , [ ` readMap<T> ` ] [ readMap ] .
45+ 4 . Read the compile-time constant values using the extension method: [ ` read<T> ` ] [ read ] . <br />
46+
47+ To read constant of a user-defined type ` U ` , add a suitable ` Decoder<U> ` :
48+ ``` Dart
49+ Reader.addDecoder<U>(decoder);
50+
51+ ```
52+
53+ To read a constant representing a * collection* of a * user-defined* type ` U `
54+ use the convenience methods [ ` readList<U> ` ] [ readList ] ,
55+ [ ` readSet<U> ` ] [ readSet ] , [ ` readMap<K,U> ` ] [ readMap ] , and [ ` readIterator<U> ` ] [ readIterator ] .
56+ On first use, these methods register a decoder making the types:
57+ ` List<U> ` , ` Set<U> ` , ` Map<K,U> ` , ` Iterable<U> ` readable with [ ` read<U> ` ] [ read ] .
58+
4259
43605 . Use the constant values to generate the source-code and complete the building
4461process.
@@ -49,7 +66,6 @@ The extension [`Reader`][Reader] provides a systematic method of
4966retrieving constants of
5067arbitrary data-types by allowing users to register ` Decoder ` objects.
5168
52-
5369` Decoder<T> ` is an abstract
5470parameterized class with a method ` T read<T>(DartObject obj) `
5571that attempt to read a variable of type ` T ` from ` obj ` and return the result.
@@ -85,7 +101,7 @@ Read.addDecoder(const AnnotationDecoder());
85101
86102The example below show how to register a decoder for a Dart ` Enum ` and read
87103an instance of the enumeration. In this case, instead of creating a custom
88- decoder class we just register an instance of the already defined generic class
104+ decoder class we register an instance of the already defined generic class
89105[ ` EnumDecoder ` ] [ EnumDecoder ] :
90106
91107<details > <summary > Click to show source-code. </summary >
@@ -138,6 +154,9 @@ Future<void> main() async {
138154```
139155</details >
140156
157+
158+ <br />
159+
141160The program listed below show how to read a constant of type
142161` List<List<String>> ` :
143162
@@ -188,13 +207,19 @@ Future<void> main() async {
188207 print('\nlistObj.readList<$listOfString>(): $list3\n');
189208}
190209```
210+
191211</details >
192212
213+
214+ <br />
215+
193216The program above produces the following terminal output:
194217
218+
195219<details > <summary > Click to show terminal output. </summary >
196220
197- ```
221+
222+ ``` Term
198223$ dart example/bin/list_example.dart
199224
200225Reading library: example
@@ -205,10 +230,12 @@ Reading library: example
205230
206231Adding decoder for List<String> and List<List<String>>
207232
233+
208234Reader:
209- Registered types: (bool, double, int, num,
210- String, Symbol, Type, List<String>, List<List<String>>)
211- Mapped types : {}
235+ Decodable types: [bool, double, int, num, String, Symbol, Type,
236+ List<bool>, ..., Iterable<Type>, List<List<String>>]
237+ Resolved types: {}
238+
212239
213240listObj.read<List<List<String>>>: [[a], [b]]
214241
0 commit comments