In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Editor to share with you about the List collection serialization into the Xml file example analysis, I believe that most people do not know much about it, so share this article for your reference, I hope you will learn a lot after reading this article, let's go to know it!
What is serialization first? What's the use? Serialization (Serialization) the process of converting an object's state information into a form that can be stored or transmitted. During serialization, the object writes its current state to a temporary or persistent store. Later, you can recreate the object by reading or deserializing its state from the store.
Serialization enables other code to view or modify object instance data that cannot be accessed without serialization. Specifically, code serialization requires special permissions: the SecurityPermission that specifies the SerializationFormatter flag. Under the default policy, code downloaded through Internet or Intranet code is not granted this permission; only code on the local computer is granted this permission.
Typically, all fields of an object instance are serialized, which means that the data is represented as serialized data for the instance. In this way, code that can interpret the format may be able to determine the value of the data without relying on the accessibility of the member. Similarly, deserialization extracts data from the serialized representation and sets the object state directly, which is also independent of accessibility rules.
For any object that may contain important security data, you should make it unserializable if possible. If it must be serializable, try generating specific fields to hold important non-serializable data. If this cannot be achieved, you should be aware that the data is exposed to any code that has serialization permission, and make sure that no malicious code is allowed to gain that permission.
To sum up: serialization is a complex object transformation stream that facilitates our storage and information exchange. I don't know much about security, mainly if some information is to be kept secret, it is defined as unserializable to prevent others from deserializing it.
List collection serialization writes to Xml file
(1) first create a person class that includes three attributes of name,age,email.
Public class person {public string Name {set; get;} [XmlIgnore] public int Age {get; set;} public string Email {get; set;}}
Note: [XmlIgnore] in the above code is a non-serializable operation on the Age property. This is a non-serializable feature that is unique to Xml serializers. For other objects, use [NonSerialized].
(2) xml serialization is realized by adding data to list collection.
List list=new List (); list.Add (new person () {Name = "istari", Age = 22, Email = "1061399756@qq.com"}); list.Add (new person () {Name = "ss", Age = 22, Email = "1061399756@qq.com"}); list.Add (new person () {Name = "ww", Age = 22, Email = "521@qq.com"}) / / implement xml serialization XmlSerializer xml = new XmlSerializer (typeof (List)); using (FileStream fs=File.OpenWrite ("List.xml")) {xml.Serialize (fs, list);} Console.WriteLine ("OK"); Console.ReadKey ()
(3) Result
Istari 1061399756@qq.com ss 1061399756@qq.com ww 521@qq.com above is all the content of the article "sample analysis of serialization of List collections into Xml files". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.