ConfigSection Class
The ConfigSection class provides a series of methods for type conversion which simplifies data manipulation.
Common Use Methods
Name | Description |
---|---|
AsArray | Retrieves a value as an array of objects (object[] ) |
AsArray<T> | Retrieves a value as an array of the specified type T |
AsBoolean | Retrieves a value as System.Boolean |
AsConfigItem | Returns the ConfigItem on the specified |
AsConfigSection | Retrieves a value as a ConfigSection (aka Sub-Sections) |
AsDateTime | Retrieves a value as System.DateTime |
AsDecimal | Retrieves a value as System.Decimal |
AsDouble | Retrieves a value as System.Double |
AsFloat | Retrieves a value as System.Float |
AsInt | Retrieves a value as System.Int32 |
AsList | Retrieves a value as a list of objects (List<object> ) |
AsList<T> | Retrieves a value as a list of the specified type T |
AsLong | Retrieves a value as System.Int64 |
AsRegex | Retrieves a valiue as a Regex |
AsSecureString | Retrieves a value as a SecureString |
AsString | Retrieves a value as System.String |
Section | Retrieves a value as a ConfigSection (aka Sub-Sections) |
Usage
Let's take the below YAML/JSON configuration as example:
ProcessName: MY_BUSINESS_NAME
LocalRecovery:
MaxRetries: 3
LogMessage: "Retrying {0} of 3..."
Processes: [CHROME, EXCEL, OUTLOOK]
Credentials:
System1:
ServerAddress: "system1.address.com"
Username: "US1"
System2:
ServerAddress: "system2.address.com"
Username: "US2"
{
"ProcessName": "MY_BUSINESS_NAME",
"LocalRecovery": {
"MaxRetries": 3,
"LogMessage": "Retrying {0} of 3..."
},
"Processes": [
"CHROME",
"EXCEL",
"OUTLOOK"
],
"Credentials": {
"System1": {
"ServerAddress": "system1.address.com",
"Username": "US1"
},
"System2": {
"ServerAddress": "system2.address.com",
"Username": "US2"
}
}
}
ProcessName and Processes are simple keys-value pairs while LocalRecovery and Credentials are sub-sections.
After read the above configuration using Read Config File activity and getting access to ConfigSection object, e.g Config
, we can retrieve each value as showing on the syntax below:
Config("Key")
Config("Section/Key")
Config("Section1/Section2/SectionN.../Key")
Config["Key"]
Config["Section/Key"]
Config["Section1/Section2/SectionN.../Key"]
To create a new key-value pair or update you can use:
Config("NewKey") = "MyValue"
Config("Section/ExistingKey") = 100
Config("Section/NewSection/Key") = { "A", "B" }
Config["NewKey"] = "MyValue"
Config["Section/ExistingKey"] = 100
Config["Section/NewSection/Key"] = new [] { "A", "B" }
When setting a value, in case of a section does not exist it will be created automatically.
By default, all values are boxed on the type object
. Read more at Boxing and Unboxing.
You need then convert the values to the type you need (except Sections) using the conventional way or using the handy methods provided by ConfigSection class, e.g:
Conventional | ConfigSection Methods |
---|---|
Config("ProcessName").ToString |
Config.AsString("ProcessName") |
CInt(Config("LocalRecovery/MaxRetries")) |
Config.AsInt("LocalRecovery/MaxRetries") |
CType(Config("Credentials/System1), ConfigSection) |
Config.Section("Credentials/System1") |
New Regex(Config("EmailRegexPattern").ToString) |
Config.AsRegex("EmailRegexPattern") |
Conventional | ConfigSection Methods |
---|---|
Config["ProcessName"].ToString() |
Config.AsString("ProcessName") |
(int)Config("LocalRecovery/MaxRetries") |
Config.AsInt("LocalRecovery/MaxRetries") |
(ConfigSection)Config["Credentials/System1"] |
Config.Section("Credentials/System1") |
new Regex(Config["EmailRegexPattern"].ToString()) |
Config.AsRegex("EmailRegexPattern") |
Key paths are case-insensitive
To retrieve values from the configuration file, you don't need to worry with the letter case.
RETRIES: 123
MESSAGES:
init: 'Initializing...'
Config.AsInt("retries")
Config.AsString("messages/INIT")
Other Methods
Name | Description |
---|---|
Parent | Returns the parent section of the current section |
Root | Returns the top level section |
Traverse | Returns all config items from all section levels |
Inspect | Returns all key-pair values from all section levels (useful for debug) |