You are developing an application. The application converts a Location object to a string by using a method
named WriteObject. The WriteObject() method accepts two parameters, a Location object and an
XmlObjectSerializer object. The application includes the following code. (Line numbers are included for
reference only.)
01 public enum Compass
02 {
03 North,
04 South,
05 East,
06 West
07 }
08 [DataContract]
09 public class Location
10 {
11 [DataMember]
12 public string Label { get; set; }
13 [DataMember]
14 public Compass Direction { get; set; }
15 }
16 void DoWork()
17 {
18 var location = new Location { Label = “Test”, Direction = Compass.West};
19 Console.WriteLine(WriteObject(location,
20
21 ));
22 }
You need to serialize the Location object as XML. Which code segment should you insert at line 20?
A.
new XmlSerializer(typeof(Location))
B.
new NetDataContractSerializer()
C.
new DataContractJsonSerializer(typeof (Location))
D.
new DataContractSerializer(typeof(Location))
Explanation:
The code is using [DataContract] attribute here so need to used DataContractSerializer class.