Evaluation of Variables
In your configurations you can use variables which can take values of configuration tree nodes.
To get the value of some node construction $(path_to_the_node)
is used (for more details about paths see Navigation section).
Besides that you can work with environment variables (~name_of_variable)
and you can even make your own variables resolver.
Also to expand the functionality of variables macro inserts (::macro_name)
can be added.
Let confStr
string variable contains the following configuration section:
root
{
name="Jake"
last_name="Snowman"
full_name="$(/$name) $(/$last_name)" {}
DOB="1982/05/12"
details
{
doc1=c:\documents\
doc2=\snowman
var1=$(../var2) {}
var2=$(../var1) {}
env_var=$(~USERNAME) // "~" - environment variable
nowis=$(::now) // "::" - macro
}
}
The code
var conf = LaconicConfiguration.CreateFromString(confStr);
var result = pattern.EvaluateVarsInConfigScope(conf);
will output navigation result depending on pattern
variable value:
$(/$name) - "Jake"
$(/full_name) - "Jake Snowman"
$(/details/$doc1)$(/details/$doc2) - "c:\documents\snowman"
$(/details/var1) - endless loop (throws exception)
$(/non-existent|/$name) - "Jake"
$(!/non-existent) - nonexisting required (throws exception)
$(/details/$env_var) - "User"
$(/details/$nowis) - current datetime
$(/just_name::as-string dflt="Anderson") - "Anderson"