TConfigurationBinder Class
Fills objects with the values of a configuration section.
Remarks
The same operation as IConfiguration.Bind, plus a form that creates the object:
Options := TConfigurationBinder.Bind<TServerOptions>(Config);
A member can be a string, an integer or a boolean, any other type the JSON framework converts (an enumeration, a floating point number, a date, a Nullable), an object, a list of any of these, or a dynamic array of anything but objects. The class of the items of a list must be declared in the interface section of a unit: it is located by name at run time, and a type declared anywhere else cannot be found.
A member whose key is absent keeps the value it has, which is how the constructor of the class provides defaults - unless it is marked [Required], which makes the absence an error. The other validation attributes, and the methods marked [OnValidate], are applied to the resulting values. An object member that is nil is created, and it is up to the destructor of the class to free it.
Binding does not stop at the first problem: all of them are reported in a single EConfigurationException.
Syntax
Unit: Bcl.Configuration.Binder
TConfigurationBinder = class(TObject);
Methods
| Name | Description |
|---|---|
| Bind | Overloaded Bind(IConfiguration, TUnknownMemberHandling) Bind(IConfiguration, TObject, TUnknownMemberHandling) |