using System; using System.Collections.Generic; namespace FlexFramework.Excel { /// /// Default converter for /// /// Key type /// Value type /// Valid pattern is [key,value][key,value]...; /// if elements contain , and/or [ and/or ], use \,, \[, \] instead public sealed class DictionaryConverter : CustomConverter> { /// /// Convert input string to /// /// Input value /// Valid pattern is [key,value][key,value]...; /// if elements contain , and/or [ and/or ], use \,, \[, \] instead /// Parsed value /// Dictionary key is duplicate public override Dictionary Convert(string input) { if (string.IsNullOrEmpty(input)) return null; Dictionary dict = new Dictionary(); foreach (string group in SplitGroup(input, '[', ']')) { string[] pair = Split(group, ','); TKey key = ValueConverter.Convert(pair[0]); TValue value = ValueConverter.Convert(pair[1]); if (dict.ContainsKey(key)) throw new FormatException("Dictionary key is duplicate: " + key); dict.Add(key, value); } return dict; } } }