Exemple #1
0
        /// <summary>
        /// 保存对象到特定格式的XML文件
        /// </summary>
        /// <param name="path">XML文件路径.</param>
        /// <param name="obj">待保存的对象</param>
        public static void SaveObjectToXml(string path, object obj)
        {
            string xml = XmlConvertor.ObjectToXml(obj, true);

            using (StreamWriter writer = new StreamWriter(path))
            {
                writer.Write(xml);
            }
        }
Exemple #2
0
        /// <summary>
        /// 从XML文件转换为Object对象类型.
        /// </summary>
        /// <param name="path">XML文件路径</param>
        /// <param name="type">Object对象类型</param>
        /// <returns></returns>
        public static object LoadObjectFromXml(string path, Type type)
        {
            object obj = null;

            using (StreamReader reader = new StreamReader(path))
            {
                string content = reader.ReadToEnd();
                obj = XmlConvertor.XmlToObject(content, type);
            }
            return(obj);
        }