void ISerializable.GetObjectData(SerializationInfo info, StreamingContext context)
 {
     if (ExtensionData != null)
     {
         var xml = DataContractSerializerHelper.GetXml(new ExtensionDataObjectSerializationContractProxy {
             ExtensionData = this.ExtensionData
         });
         info.AddValue("ExtensionData", xml);
     }
 }
예제 #2
0
    public static void TestSimple()
    {
        var item1 = new Item {
            Id = 1
        };
        var item2 = new Item {
            Id = 2
        };

        item1.SubItem = item2;
        var xml = DataContractSerializerHelper.GetXml(new[] { item1, item2 });

        Debug.WriteLine(xml);
    }
예제 #3
0
    public static void Test()
    {
        var response = CreateTest();

        try
        {
            var xml = DataContractSerializerHelper.GetXml(response);
            Debug.Write(xml);
        }
        catch (Exception ex)
        {
            Debug.Assert(false, ex.ToString());
        }
    }
    public static void Test()
    {
        var test = new TestConfiguration();

        Debug.WriteLine("\nTesting Xmlserializer...");
        var xml = XmlSerializationHelper.GetXml(test);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromXml = XmlSerializationHelper.LoadFromXML <TestConfiguration>(xml);
            Debug.WriteLine("XmlSerializer result: " + testFromXml.ToString());
        }
        Debug.WriteLine("\nTesting Json.NET...");
        var json = JsonConvert.SerializeObject(test, Formatting.Indented);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromJson = JsonConvert.DeserializeObject <TestConfiguration>(json);
            Debug.WriteLine("Json.NET result: " + testFromJson.ToString());
        }
        Debug.WriteLine("\nTesting DataContractSerializer...");
        var contractXml = DataContractSerializerHelper.GetXml(test);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromContractXml = DataContractSerializerHelper.LoadFromXML <TestConfiguration>(contractXml);
            Debug.WriteLine("DataContractSerializer result: " + testFromContractXml.ToString());
        }
        Debug.WriteLine("\nTesting BinaryFormatter...");
        var binary = BinaryFormatterHelper.ToBase64String(test);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromBinary = BinaryFormatterHelper.FromBase64String <TestConfiguration>(binary);
            Debug.WriteLine("BinaryFormatter result: " + testFromBinary.ToString());
        }
        Debug.WriteLine("\nTesting JavaScriptSerializer...");
        var javaScript = new JavaScriptSerializer().Serialize(test);

        using (new SetValue <bool>(TestConfiguration.ShowDebugInformation, true))
        {
            var testFromJavaScript = new JavaScriptSerializer().Deserialize <TestConfiguration>(javaScript);
            Debug.WriteLine("JavaScriptSerializer result: " + testFromJavaScript.ToString());
        }
    }
    public static void Test()
    {
        var response = CreateTest();

        try
        {
            var xml = DataContractSerializerHelper.GetXml(response);
            Debug.Write(xml);
            var newResponse = DataContractSerializerHelper.GetObject <CFCConnectResponse>(xml);
            Debug.Assert(newResponse != null);
            Debug.Assert(response.StatusCode == newResponse.StatusCode);
            Debug.Assert(response.StatusDescription == newResponse.StatusDescription);
            Debug.Assert(newResponse.Comments.SequenceEqual(response.Comments));
        }
        catch (Exception ex)
        {
            Debug.Assert(false, ex.ToString());
        }
    }
    public static void Test()
    {
        Student kid = new Student();

        kid.Id        = Guid.NewGuid();
        kid.FirstName = "foo";
        kid.LastName  = "bar";
        DataContractSerializer dcs = new DataContractSerializer(
            typeof(Student),
            new Type [] { typeof(StudentId) },
            Int32.MaxValue,
            false, true, new StudentSurrogate());

        SerializationFlags.StudentGuidOnly = false;
        string xml1 = DataContractSerializerHelper.GetXml(kid, dcs);

        SerializationFlags.StudentGuidOnly = true;
        string xml2 = DataContractSerializerHelper.GetXml(kid, dcs);
    }