PrepAway - Latest Free Exam Questions & Answers

You need to ensure that the application preserves the e…

DRAG DROP
An application serializes and deserializes XML from streams. The XML streams are in the following format:

The application reads the XML streams by using a DataContractSerializer object that is declared by the
following code segment:
var ser = new DataContractSerializer(typeof(Name));
You need to ensure that the application preserves the element ordering as provided in the XML stream.How should you complete the relevant code? (To answer, drag the appropriate attributes to the correct
locations in the answer area-Each attribute may be used once, more than once, or not at all. You may need to
drag the split bar between panes or scroll to view content.)
Select and Place:

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:
DataContractAttribute – Specifies that the type defines or implements a data contract and is serializable by a
serializer, such as the DataContractSerializer. To make their type serializable, type authors must define a data
contract for their type.
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datacontractattribute.aspx
DataMemberAttribute – When applied to the member of a type, specifies that the member is part of a data
contract and is serializable by the DataContractSerializer.http://msdn.microsoft.com/en-us/library/ms574795.aspx

2 Comments on “You need to ensure that the application preserves the e…

  1. Swapnil says:

    [DataContract (Namespace =”http://www.contoso.com/2012/06″)]
    public class Name
    {
    [DataMember(Order =10)]
    public string FirstName { get; set; }
    [DataMember]
    public string LastName { get; set; }
    }
    class Program
    {
    public void Dowork()
    {
    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Location));
    var location = new Location { Label = “Test”, Direction = Compass.West };
    System.IO.FileStream fs = new System.IO.FileStream(“D:\\hello2.txt”, System.IO.FileMode.OpenOrCreate);

    ser.WriteObject(fs, location);
    Console.WriteLine(“Serialized”);
    }
    static void Main(string[] args)
    {

    DataContractSerializer ser = new DataContractSerializer(typeof(Name));
    var name = new Name { FirstName=”First”,LastName=”Last”};
    System.IO.FileStream fs = new System.IO.FileStream(“D:\\hello2.txt”, System.IO.FileMode.OpenOrCreate);
    ser.WriteObject(fs, name);
    Console.WriteLine(“Serialized”);




    2



    0

Leave a Reply