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.

Definition

Namespace: Gemstone.StringExtensions
Assembly: Gemstone.Common (in Gemstone.Common.dll) Version: 1.0.128 -- Release Build+d050cfc5563c89a1188cc3c6b2d417530856f490
public static Dictionary<string, string> ParseKeyValuePairs(
	this string? value,
	char parameterDelimiter = ';',
	char keyValueDelimiter = '=',
	char startValueDelimiter = '{',
	char endValueDelimiter = '}',
	bool ignoreDuplicateKeys = true
)

Parameters

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, String
Dictionary 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).

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.

Exceptions

ArgumentNullExceptionvalue is null.
ArgumentExceptionAll delimiters must be unique -or- all keys must be unique when ignoreDuplicateKeys is set to false.
FormatExceptionTotal nested key/value pair expressions are mismatched -or- encountered endValueDelimiter before startValueDelimiter.

See Also