예제 #1
0
    public static void Test()
    {
        var xml      = XmlProvider.GetXml(); // Returns the long XML string from the post.
        var matchSet = XmlSerializationHelper.LoadFromXML <matchset>(xml);

        Debug.WriteLine(matchSet.GetXml());
    }
    private void ExecutedLoadXML(object sender, ExecutedRoutedEventArgs e)
    {
        string xml      = @"<plan xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xsi:noNamespaceSchemaLocation=""schema.xsd"">
      <nagłówek>
        <autorzy>
          <nazwa>Autorzy:</nazwa>
          <autor atr=""one"">
            <numer>222</numer>
            <imię>Rust</imię>
            <nazwisko>Snow</nazwisko>
          </autor>
          <autor>
            <numer>111</numer>
            <imię>Ian</imię>
            <nazwisko>Nower</nazwisko>
          </autor>
        </autorzy>
      </nagłówek>
    </plan>
    ";
        var    plan     = XmlSerializationHelper.LoadFromXML <plan>(xml);
        var    children = new List <plan>();

        children.Add(plan);
        treeView1.ItemsSource = null;
        treeView1.Items.Clear();
        treeView1.ItemsSource = children;
    }
    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());
        }
    }