Beispiel #1
0
        private static KeyValuePair <string, string> ParseKeyAndValue(ConfigurationTokenStream tokens, string section)
        {
            // Get the key.
            var key = tokens.Current.Value;

            tokens.Consume();
            if (ContainsWhiteSpace(key))
            {
                const string message = "The key '{0}' contains whitespace.";
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, message, key));
            }

            // Expect the equality sign.
            tokens.Expect(ConfigurationTokenKind.Equals, "Expected to find '=' token.");
            tokens.Consume();

            // Get the value.
            tokens.Expect(ConfigurationTokenKind.Value, "Expected to find value.");
            var value = tokens.Current.Value;

            tokens.Consume();

            // Append section to key?
            if (!string.IsNullOrWhiteSpace(section))
            {
                key = string.Concat(section, "_", key);
            }
            return(new KeyValuePair <string, string>(key, value));
        }
Beispiel #2
0
        private static string ParseSection(ConfigurationTokenStream tokens)
        {
            var value = tokens.Current.Value;

            if (ContainsWhiteSpace(value))
            {
                throw new InvalidOperationException("Sections cannot contain whitespace.");
            }
            tokens.Consume();
            return(value);
        }