public static void ToXml <TKey, TValue> (this IDictionary <TKey, TValue> dictionary, string filePath) { DictionaryWrapper <TKey, TValue> wrapper = new DictionaryWrapper <TKey, TValue> (dictionary); XmlSerializer serializer = MakeXmlSerializer <DictionaryWrapper <TKey, TValue> > (); TextWriter textWriter = new StreamWriter(filePath); serializer.Serialize(textWriter, wrapper); textWriter.Close(); }
private static void DeserializeDictionary <TKey, TValue> (IDictionary <TKey, TValue> dictionary, string filePath, bool unityResource) { XmlSerializer deserializer = MakeXmlSerializer <DictionaryWrapper <TKey, TValue> > (); TextReader textReader = null; if (unityResource) { TextAsset text = Resources.Load(filePath, typeof(TextAsset)) as TextAsset; textReader = new StringReader(text.text); } else { textReader = new StreamReader(filePath); } DictionaryWrapper <TKey, TValue> wrapper = (DictionaryWrapper <TKey, TValue>)deserializer.Deserialize(textReader); wrapper.GetMap(ref dictionary); textReader.Close(); }