|
StringExtensionsParseKeyValuePairs Method
|
Parses key/value pair expressions from a string. Parameter pairs are delimited by keyValueDelimiter
and multiple pairs separated by parameterDelimiter. Supports encapsulated nested expressions.
Namespace: GSFAssembly: GSF.Core (in GSF.Core.dll) Version: 2.4.218-beta+101eee949414e414795e55a6e73d88938f0177b8
Syntax [<ExtensionAttribute>]
static member ParseKeyValuePairs :
value : string *
?parameterDelimiter : char *
?keyValueDelimiter : char *
?startValueDelimiter : char *
?endValueDelimiter : char *
?ignoreDuplicateKeys : bool
(* Defaults:
let _parameterDelimiter = defaultArg parameterDelimiter ';'
let _keyValueDelimiter = defaultArg keyValueDelimiter '='
let _startValueDelimiter = defaultArg startValueDelimiter '{'
let _endValueDelimiter = defaultArg endValueDelimiter '}'
let _ignoreDuplicateKeys = defaultArg ignoreDuplicateKeys true
*)
-> Dictionary<string, string>
GSF.StringExtensions.ParseKeyValuePairs = function(value, parameterDelimiter, keyValueDelimiter, startValueDelimiter, endValueDelimiter, ignoreDuplicateKeys);
View SourceParameters
- value String
- String containing key/value pair expressions to parse.
- parameterDelimiter Char (Optional)
- Character that delimits one key/value pair from another.
- keyValueDelimiter Char (Optional)
- Character that delimits key from value.
- startValueDelimiter Char (Optional)
- Optional character that marks the start of a value such that value could contain other
parameterDelimiter or keyValueDelimiter characters.
- endValueDelimiter Char (Optional)
- Optional character that marks the end of a value such that value could contain other
parameterDelimiter or keyValueDelimiter characters.
- ignoreDuplicateKeys Boolean (Optional)
- Flag determines whether duplicates are ignored. If flag is set to false an
ArgumentException will be thrown when all key parameters are not unique.
Return Value
DictionaryString,
StringDictionary of key/value pairs.
Usage Note
In Visual Basic and C#, you can call this method as an instance method on any object of type
String. When you use instance method syntax to call this method, omit the first parameter. For more information, see
Extension Methods (Visual Basic) or
Extension Methods (C# Programming Guide).
Exceptions Exception | Condition |
---|
ArgumentNullException | value is null. |
ArgumentException | All delimiters must be unique -or- all keys must be unique when
ignoreDuplicateKeys is set to false. |
FormatException | Total nested key/value pair expressions are mismatched -or- encountered
endValueDelimiter before startValueDelimiter. |
Remarks
Parses a string containing key/value pair expressions (e.g., "localPort=5001; transportProtocol=UDP; interface=0.0.0.0").
This method treats all "keys" as case-insensitive. Nesting of key/value pair expressions is allowed by encapsulating the
value using the startValueDelimiter and endValueDelimiter values (e.g.,
"dataChannel={Port=-1;Clients=localhost:8800}; commandChannel={Port=8900}; dataFormat=FloatingPoint;"). There must be one
endValueDelimiter for each encountered startValueDelimiter in the value or a
FormatException will be thrown. Multiple levels of nesting is supported. If the ignoreDuplicateKeys
flag is set to false an ArgumentException will be thrown when all key parameters are not unique. Note
that keys within nested expressions are considered separate key/value pair strings and are not considered when checking
for duplicate keys.
See Also