public static SerializableStringDictionary ToSerializableStringDictionary(this StringCollection sc) { if (sc == null || sc.Count % 2 != 0) { throw new InvalidDataException("null or broken dictionary"); } var dic = new SerializableStringDictionary(); for (var i = 0; i < sc.Count; i += 2) { dic.Add(sc[i], sc[i + 1]); } return(dic); }
//TODO: Maybe move this into Utils? It is quite general method private static void ReadMap(SerializableStringDictionary map, TextReader reader, string mapName) { map.Clear(); var mappings = reader.ReadLine().Replace(string.Format("{0}:", mapName), string.Empty).Split(new[] { ';' }, StringSplitOptions. RemoveEmptyEntries); foreach (string mapping in mappings) { var parts = mapping.Split(new[] { ':' }, StringSplitOptions.RemoveEmptyEntries); map.Add(parts[0], parts[1]); } }
/// <summary> /// Handles setting of a value in the StringValues Dictionary /// </summary> /// <param name="value">Value to Set</param> /// <param name="name">Compiler Generated Name of the Property</param> public void SetString(string value, [CallerMemberName] string name = null) { if (name == null) { return; } if (StringValues.ContainsKey(name)) { StringValues[name] = value; } else { StringValues.Add(name, value); } }
//TODO: Maybe move this into Utils? It is quite general method private static void ReadMap(SerializableStringDictionary map, TextReader reader, string mapName) { map.Clear(); var mappings = reader.ReadLine().Replace(string.Format("{0}:", mapName), string.Empty).Split(new[] {';'}, StringSplitOptions. RemoveEmptyEntries); foreach (string mapping in mappings) { var parts = mapping.Split(new[] {':'}, StringSplitOptions.RemoveEmptyEntries); map.Add(parts[0], parts[1]); } }