C# xml 序列化 喔幹花了我一天 序列化

  • 76
  • 0
  • 2018-04-19

C# xml 喔幹花了我一天

   using (XmlWriter writer = XmlWriter.Create("Agreement.xml"))
                {
                    DataContractSerializer serializer1 = new DataContractSerializer(o.GetType());
                    serializer1.WriteObject(writer, o);
                }


  [DataContract(Name = "Devices", Namespace = "")]
    public partial class Devices
    {       
        public Devices()
        {
            Materials = new HashSet<Materials>();
        }
        [DataMember()]
        public Guid ID { get; set; }

}

還有最重要的

Configuration.ProxyCreationEnabled = false;