Serialize exploration Attempt

Source: Internet
Author: User

Serialize exploration Attempt
Key points to be considered at the beginning of the design are:
1. Does the data structure support Web Service?
2. Whether to support persistence objects in an XML structure and not conflict with Contract persistence is a supplement
3. When the. net Object breaks down the remote boundary, consider supporting runtime persistence.
4. Avoid using XML and Runtime technologies when only common persistence is required.

XML Serial
After using Dotnet for so long, I have hardly used Serial technology.

Open Systemopen System. IO [<CLIMutable>] // This feature must be added here, so that this Recode has a default constructor type DateSerTest = {Local: DateTime; Utc: dateTime} let ser = new System. xml. serialization. xmlSerializer (typeof <DateSerTest>) let d = {Local = DateTime. specifyKind (new DateTime (2014, 10, 1), DateTimeKind. local) Utc = DateTime. specifyKind (new DateTime (2014, 10, 1), DateTimeKind. utc)} let testSerialization (dt: DateSerTest) = use MS = New IO. memoryStream () ser. serialized (MS, o = dt) let result = Text. encoding. default. getString (ms. getBuffer () ms. close () resultlet objecblock = testSerialization d // get the Xml byte stream from the memory stream. The stream is the data is the media, and the Serializer is the template. Let MS = new IO. MemoryStream (Text. Encoding. Unicode. GetBytes (objecblock) let newd = ser. Deserialize (MS):?> DateSerTest // generate the object if d = newd then prrintfn "Equal"

Modify the memory stream to a file stream, and then perform the following test to get the same result.

let testFileSerialization(dt:DateSerTest) =    let filename = "serialization.xml"    use ms = new StreamWriter(filename)    ser.Serialize(ms, o = dt)    ms.Close()testFileSerialization dlet ms = new StreamReader("serialization.xml")let newd = ser.Deserialize(ms) :?> DateSerTestif d = newd then printfn "Equal"

Classes can be more complex. In special cases, you need to add specific attributes for special definitions. Above

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.