• 序列化和反序列化


        /// <summary>
            /// 读取XML文件,反序列化为对象
            /// </summary>
            /// <typeparam name="T">对象类型</typeparam>
            /// <param name="t">对象</param>
            /// <param name="fileName">xml文件名</param>
            /// <returns>反序列化的对象</returns>
            public static T ReadXMLFileToType<T>(T t, string xmlFileName)
            {
                XmlSerializer xs = new XmlSerializer(t.GetType());
                XmlTextReader reader = new XmlTextReader(xmlFileName);
                reader.Normalization = false;
                t = (T)xs.Deserialize(reader);
                reader.Close();
                return t;
            }

            /// <summary>
            /// 序列化对象,保存为XML文件,前缀为空
            /// </summary>
            /// <param name="t">对象类型</param>
            /// <param name="s">对象序列化后的Xml文件</param>
            public static void SaveTypeToXmlFile<T>(T t, string xmlFile)
            {
                XmlSerializer xs = new XmlSerializer(t.GetType());
                TextWriter writer = new StreamWriter(xmlFile);
                XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
                ns.Add(String.Empty, String.Empty);
                xs.Serialize(writer, t, ns);
                writer.Flush();
                writer.Close();
            }
        }

  • 相关阅读:
    CF1462E2 Solution
    CF1450D Solution
    CF1451D Solution
    CF1442B Solution
    CF1453C Solution
    CF1455D Solution
    linux服务器部署node项目
    原生javascript实现 hasClass addClass removeClass
    图片加载完执行函数
    MySQL
  • 原文地址:https://www.cnblogs.com/Veakey/p/2674612.html
Copyright © 2020-2023  润新知