Summary
Value method allows to de-serialize typed data value. Both, simple types, such as Integer or string, and complex types, such as records, objects or arrays can be de-serialized using Value method.
Syntax
function Value<T>: T; overload;
Type Parameters
- T
- Specifies type of de-serializing value.
Return Value
De-serialized value.
Remarks
Value method can be used to read typed data values. It can be called in the following de-serializer states:
- Right after a specialized de-serializer has been created, the Value method can be called any times to de-serialize any numbers of previously serialized root values. Some specialized serializers may provide additional API, which allows to seek for a root-level value with specified name. Note, that root-level value naming is not a part of core serializer API.
- After NG.Serialization.TDeserializer.BeginArray and before corresponding NG.Serialization.TDeserializer.EndArray method calls, Value method can be called several times to de-serialize array elements. Use NG.Serialization.TDeserializer.HasNext method before calling Value method to detect, whether next array element is available.
- Inside an object serialization initiated by NG.Serialization.TDeserializer.BeginObject(string) method call, Value method can be called one time after each NG.Serialization.TDeserializer.Prop method call to read de-serializing property value. Use NG.Serialization.TDeserializer.HasNext method before a call to NG.Serialization.TDeserializer.Prop method to detect, whether the next object property is available.
The algorithm, which is used to serialize and de-serialize typed values, depends of its type. Serialization engine provides built-in support for many Delphi types. For example, an array is serialized by writing all its elements; record or object is serialized by writing all its public fields and properties. However, there are exist some possibilities to change the way in which typed values will be serialized (Look at TSerializer.Value method description). In such cases de-serialization way should be changed accordingly.
Note: |
---|
There are two overloaded Value methods. This one implements normal read mode, as opposed to fill-read mode, which is implemented in another overload. To learn more about read modes, look at NG.Serialization.FillReadAttribute description. |
Examples
Delphi | Copy Code |
---|---|
str := D.Value<string>; i := D.Value<Integer>; cust := D.Value<TMyCustomer>; |