Summary
FillReadAttribute can be applied to type or class/record member to specify that the value should be read in fill-read mode.
Syntax
FillReadAttribute = class(TSerlnAttr);
Remarks
Fill-read mode is a mode for reading by reference. The most common example is de-serializing of read-only properties of object type. In normal mode, which require read-write property, new object will be created during de-serialization, and this object will be assigned to the property as its value. In contrast, in fill-read mode the no new objects will be created; instead, the existing object reference will be read from the property and de-serialization will be performed into fields and properties of this existing object. Another common example of fill-read mode are collections: usually a collection itself is accessible through read-only property and should not be replaced with another collection instance during de-serialization; it should be only re-filled with new items.
Since fill-read mode is a mode for reading by reference, the value itself can't be modified during fill-read. So, for example, for object properties the value is a reference to object, and it remains constant during fill-read, that is - after fill-read it points to the same object. This is the main rule of fill-read semantic. However, fill-read mode can be used not only with objects. Generally, fill-read is supported in following types:
- Classes.
- Records: All members of fill-read record should be also explicitly marked as fill-read using FillReadAttribute.
- Static arrays: If static array is used in fill-read mode, then fill-read mode should be also specified for array elements using NG.Serialization.ElemFillReadAttribute.
- Dynamic arrays: since the dyn-array is a reference, fill-read mode for array elements is not required; but, can be specified, if needed. However, in any case the length of the array cannot be changed during fill-read, because the array value, which is reference to array data, should remains constant.
- Any other type with custom converter, which work in fill-read mode; see also: TConverter. Basically, using converters, fill-read concept becomes consistent across all possible types.
Examples
Delphi | Copy Code |
---|---|
type TMyObject = class public [FillRead] property SubObject: TMySubObject: read FSubObject; end; |
Delphi | Copy Code |
---|---|
type [Converter(TObjectByIdConverter)] TBusinessObjectId = type Integer; procedure TMyPointConverter.Read(D: TDeserializer; var V); var id: TBusinessObjectId; obj: TBusinessObject; begin // Work in fill-read mode; V value is just logical reference // to object. We do not change it, instead referred object // content will be changed. id := TBusinessObjectId(V); obj := GetBusineessObjectyId(id); D.Value<TBusinessObject>(obj); end; |