public static DictionaryXmlStore <TKey, TValue> Import(string path, string keyProperty) { var serializer = new XmlSerializer(typeof(List <TValue>)); FileStream fileStream = new FileStream(path, FileMode.Open); List <TValue> items; try { items = (List <TValue>)serializer.Deserialize(fileStream); } catch { items = new List <TValue>(); } fileStream.Close(); var dictionary = new DictionaryXmlStore <TKey, TValue>(); foreach (var item in items) { TKey key = (TKey)item.GetType().GetProperty(keyProperty).GetValue(item, null); dictionary.Add(key, item); } dictionary.keyProperty = keyProperty; return(dictionary); }
public static new FunctionContainer Import(string path, string keyProperty) { var functions = new FunctionContainer(); var import = DictionaryXmlStore <string, FunctionDefinition> .Import(path, keyProperty); import.ForEach(i => functions.Add(i.Value)); return(functions); }