-Incremented version to 4.0.8
-Added VersionConverter -Fixed converting XML to JSON with a default namespace -Changed Silverlight/Windows Phone assemblies to not be signed
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
#region License
|
||||
// Copyright (c) 2007 James Newton-King
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person
|
||||
// obtaining a copy of this software and associated documentation
|
||||
// files (the "Software"), to deal in the Software without
|
||||
// restriction, including without limitation the rights to use,
|
||||
// copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the
|
||||
// Software is furnished to do so, subject to the following
|
||||
// conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be
|
||||
// included in all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
// OTHER DEALINGS IN THE SOFTWARE.
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json.Converters;
|
||||
using NUnit.Framework;
|
||||
using Newtonsoft.Json.Tests.TestObjects;
|
||||
|
||||
namespace Newtonsoft.Json.Tests.Converters
|
||||
{
|
||||
public class VersionClass
|
||||
{
|
||||
public VersionClass(string version1, string version2)
|
||||
{
|
||||
this.StringProperty1 = "StringProperty1";
|
||||
this.Version1 = new Version(version1);
|
||||
this.Version2 = new Version(version2);
|
||||
this.StringProperty2 = "StringProperty2";
|
||||
}
|
||||
|
||||
public VersionClass()
|
||||
{
|
||||
}
|
||||
|
||||
public string StringProperty1 { get; set; }
|
||||
public Version Version1 { get; set; }
|
||||
public Version Version2 { get; set; }
|
||||
public string StringProperty2 { get; set; }
|
||||
}
|
||||
|
||||
public class VersionConverterTests : TestFixtureBase
|
||||
{
|
||||
private void SerializeVersionClass(string version1, string version2)
|
||||
{
|
||||
VersionClass versionClass = new VersionClass(version1, version2);
|
||||
|
||||
string json = JsonConvert.SerializeObject(versionClass, Formatting.Indented, new VersionConverter());
|
||||
|
||||
string expectedJson = string.Format(@"{{
|
||||
""StringProperty1"": ""StringProperty1"",
|
||||
""Version1"": ""{0}"",
|
||||
""Version2"": ""{1}"",
|
||||
""StringProperty2"": ""StringProperty2""
|
||||
}}", version1, version2);
|
||||
|
||||
Assert.AreEqual(expectedJson, json);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void SerializeVersionClass()
|
||||
{
|
||||
SerializeVersionClass("1.0.0.0", "2.0.0.0");
|
||||
SerializeVersionClass("1.2.0.0", "2.3.0.0");
|
||||
SerializeVersionClass("1.2.3.0", "2.3.4.0");
|
||||
SerializeVersionClass("1.2.3.4", "2.3.4.5");
|
||||
|
||||
SerializeVersionClass("1.2", "2.3");
|
||||
SerializeVersionClass("1.2.3", "2.3.4");
|
||||
SerializeVersionClass("1.2.3.4", "2.3.4.5");
|
||||
}
|
||||
|
||||
private void DeserializeVersionClass(string version1, string version2)
|
||||
{
|
||||
string json = string.Format(@"{{""StringProperty1"": ""StringProperty1"", ""Version1"": ""{0}"", ""Version2"": ""{1}"", ""StringProperty2"": ""StringProperty2""}}", version1, version2);
|
||||
Version expectedVersion1 = new Version(version1);
|
||||
Version expectedVersion2 = new Version(version2);
|
||||
|
||||
VersionClass versionClass = JsonConvert.DeserializeObject<VersionClass>(json, new VersionConverter());
|
||||
|
||||
Assert.AreEqual("StringProperty1", versionClass.StringProperty1);
|
||||
Assert.AreEqual(expectedVersion1, versionClass.Version1);
|
||||
Assert.AreEqual(expectedVersion2, versionClass.Version2);
|
||||
Assert.AreEqual("StringProperty2", versionClass.StringProperty2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DeserializeVersionClass()
|
||||
{
|
||||
DeserializeVersionClass("1.0.0.0", "2.0.0.0");
|
||||
DeserializeVersionClass("1.2.0.0", "2.3.0.0");
|
||||
DeserializeVersionClass("1.2.3.0", "2.3.4.0");
|
||||
DeserializeVersionClass("1.2.3.4", "2.3.4.5");
|
||||
|
||||
DeserializeVersionClass("1.2", "2.3");
|
||||
DeserializeVersionClass("1.2.3", "2.3.4");
|
||||
DeserializeVersionClass("1.2.3.4", "2.3.4.5");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1285,7 +1285,7 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
Assert.AreEqual(@"<?xml version=""1.0"" encoding=""utf-8""?><root booleanType=""true"" />", xmlString);
|
||||
}
|
||||
|
||||
static void JsonBodyToSoapXml(Stream json, Stream xml)
|
||||
private static void JsonBodyToSoapXml(Stream json, Stream xml)
|
||||
{
|
||||
Newtonsoft.Json.JsonSerializerSettings settings = new Newtonsoft.Json.JsonSerializerSettings();
|
||||
settings.Converters.Add(new Newtonsoft.Json.Converters.XmlNodeConverter());
|
||||
@@ -1301,6 +1301,494 @@ namespace Newtonsoft.Json.Tests.Converters
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if !NET20
|
||||
[Test]
|
||||
public void DeserializeXNodeDefaultNamespace()
|
||||
{
|
||||
string xaml = @"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:toolkit=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"" Style=""{StaticResource trimFormGrid}"" x:Name=""TrimObjectForm"">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width=""63*"" />
|
||||
<ColumnDefinition Width=""320*"" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions xmlns="""">
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordTypedTitle"" Grid.Column=""1"" Grid.Row=""0"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordExternalReference"" Grid.Column=""1"" Grid.Row=""1"" xmlns="""" />
|
||||
<toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateCreated"" Grid.Column=""1"" Grid.Row=""2"" />
|
||||
<toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateDue"" Grid.Column=""1"" Grid.Row=""3"" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Author, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAuthor"" Grid.Column=""1"" Grid.Row=""4"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Container, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordContainer"" Grid.Column=""1"" Grid.Row=""5"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordIsEnclosed"" Grid.Column=""1"" Grid.Row=""6"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAssignee"" Grid.Column=""1"" Grid.Row=""7"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Title (Free Text Part)"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""0"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""External ID"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""1"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Date Created"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""2"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Date Due"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""3"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Author"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""4"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Container"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""5"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Enclosed?"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""6"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Assignee"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""7"" xmlns="""" />
|
||||
</Grid>";
|
||||
|
||||
string json = JsonConvert.SerializeXNode(XDocument.Parse(xaml), Formatting.Indented);
|
||||
|
||||
string expectedJson = @"{
|
||||
""Grid"": {
|
||||
""@xmlns"": ""http://schemas.microsoft.com/winfx/2006/xaml/presentation"",
|
||||
""@xmlns:x"": ""http://schemas.microsoft.com/winfx/2006/xaml"",
|
||||
""@xmlns:toolkit"": ""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"",
|
||||
""@Style"": ""{StaticResource trimFormGrid}"",
|
||||
""@x:Name"": ""TrimObjectForm"",
|
||||
""Grid.ColumnDefinitions"": {
|
||||
""ColumnDefinition"": [
|
||||
{
|
||||
""@Width"": ""63*""
|
||||
},
|
||||
{
|
||||
""@Width"": ""320*""
|
||||
}
|
||||
]
|
||||
},
|
||||
""Grid.RowDefinitions"": {
|
||||
""@xmlns"": """",
|
||||
""RowDefinition"": [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
]
|
||||
},
|
||||
""TextBox"": [
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordTypedTitle"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""0"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordExternalReference"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""1"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding Author, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordAuthor"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""4"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding Container, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordContainer"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""5"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordIsEnclosed"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""6"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordAssignee"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""7"",
|
||||
""@xmlns"": """"
|
||||
}
|
||||
],
|
||||
""toolkit:DatePicker"": [
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_DP}"",
|
||||
""@Value"": ""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordDateCreated"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""2""
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_DP}"",
|
||||
""@Value"": ""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordDateDue"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""3""
|
||||
}
|
||||
],
|
||||
""TextBlock"": [
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Title (Free Text Part)"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""0"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""External ID"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""1"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Date Created"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""2"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Date Due"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""3"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Author"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""4"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Container"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""5"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Enclosed?"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""6"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Assignee"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""7"",
|
||||
""@xmlns"": """"
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.AreEqual(expectedJson, json);
|
||||
|
||||
XNode node = JsonConvert.DeserializeXNode(json);
|
||||
|
||||
string xaml2 = node.ToString();
|
||||
|
||||
string expectedXaml = @"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:toolkit=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"" Style=""{StaticResource trimFormGrid}"" x:Name=""TrimObjectForm"">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width=""63*"" />
|
||||
<ColumnDefinition Width=""320*"" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions xmlns="""">
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordTypedTitle"" Grid.Column=""1"" Grid.Row=""0"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordExternalReference"" Grid.Column=""1"" Grid.Row=""1"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Author, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAuthor"" Grid.Column=""1"" Grid.Row=""4"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Container, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordContainer"" Grid.Column=""1"" Grid.Row=""5"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordIsEnclosed"" Grid.Column=""1"" Grid.Row=""6"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAssignee"" Grid.Column=""1"" Grid.Row=""7"" xmlns="""" />
|
||||
<toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateCreated"" Grid.Column=""1"" Grid.Row=""2"" />
|
||||
<toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateDue"" Grid.Column=""1"" Grid.Row=""3"" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Title (Free Text Part)"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""0"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""External ID"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""1"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Date Created"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""2"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Date Due"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""3"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Author"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""4"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Container"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""5"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Enclosed?"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""6"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Assignee"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""7"" xmlns="""" />
|
||||
</Grid>";
|
||||
|
||||
Assert.AreEqual(expectedXaml, xaml2);
|
||||
}
|
||||
#endif
|
||||
|
||||
[Test]
|
||||
public void DeserializeXmlNodeDefaultNamespace()
|
||||
{
|
||||
string xaml = @"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:toolkit=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"" Style=""{StaticResource trimFormGrid}"" x:Name=""TrimObjectForm"">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width=""63*"" />
|
||||
<ColumnDefinition Width=""320*"" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions xmlns="""">
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordTypedTitle"" Grid.Column=""1"" Grid.Row=""0"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordExternalReference"" Grid.Column=""1"" Grid.Row=""1"" xmlns="""" />
|
||||
<toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateCreated"" Grid.Column=""1"" Grid.Row=""2"" />
|
||||
<toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateDue"" Grid.Column=""1"" Grid.Row=""3"" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Author, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAuthor"" Grid.Column=""1"" Grid.Row=""4"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Container, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordContainer"" Grid.Column=""1"" Grid.Row=""5"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordIsEnclosed"" Grid.Column=""1"" Grid.Row=""6"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAssignee"" Grid.Column=""1"" Grid.Row=""7"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Title (Free Text Part)"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""0"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""External ID"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""1"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Date Created"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""2"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Date Due"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""3"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Author"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""4"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Container"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""5"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Enclosed?"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""6"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Assignee"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""7"" xmlns="""" />
|
||||
</Grid>";
|
||||
|
||||
XmlDocument document = new XmlDocument();
|
||||
document.LoadXml(xaml);
|
||||
|
||||
string json = JsonConvert.SerializeXmlNode(document, Formatting.Indented);
|
||||
|
||||
string expectedJson = @"{
|
||||
""Grid"": {
|
||||
""@xmlns"": ""http://schemas.microsoft.com/winfx/2006/xaml/presentation"",
|
||||
""@xmlns:x"": ""http://schemas.microsoft.com/winfx/2006/xaml"",
|
||||
""@xmlns:toolkit"": ""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"",
|
||||
""@Style"": ""{StaticResource trimFormGrid}"",
|
||||
""@x:Name"": ""TrimObjectForm"",
|
||||
""Grid.ColumnDefinitions"": {
|
||||
""ColumnDefinition"": [
|
||||
{
|
||||
""@Width"": ""63*""
|
||||
},
|
||||
{
|
||||
""@Width"": ""320*""
|
||||
}
|
||||
]
|
||||
},
|
||||
""Grid.RowDefinitions"": {
|
||||
""@xmlns"": """",
|
||||
""RowDefinition"": [
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
]
|
||||
},
|
||||
""TextBox"": [
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordTypedTitle"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""0"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordExternalReference"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""1"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding Author, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordAuthor"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""4"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding Container, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordContainer"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""5"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordIsEnclosed"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""6"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_TB}"",
|
||||
""@Text"": ""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordAssignee"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""7"",
|
||||
""@xmlns"": """"
|
||||
}
|
||||
],
|
||||
""toolkit:DatePicker"": [
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_DP}"",
|
||||
""@Value"": ""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordDateCreated"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""2""
|
||||
},
|
||||
{
|
||||
""@Style"": ""{StaticResource trimFormGrid_DP}"",
|
||||
""@Value"": ""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"",
|
||||
""@Name"": ""RecordDateDue"",
|
||||
""@Grid.Column"": ""1"",
|
||||
""@Grid.Row"": ""3""
|
||||
}
|
||||
],
|
||||
""TextBlock"": [
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Title (Free Text Part)"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""0"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""External ID"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""1"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Date Created"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""2"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Date Due"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""3"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Author"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""4"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Container"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""5"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Enclosed?"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""6"",
|
||||
""@xmlns"": """"
|
||||
},
|
||||
{
|
||||
""@Grid.Column"": ""0"",
|
||||
""@Text"": ""Assignee"",
|
||||
""@Style"": ""{StaticResource trimFormGrid_LBL}"",
|
||||
""@Grid.Row"": ""7"",
|
||||
""@xmlns"": """"
|
||||
}
|
||||
]
|
||||
}
|
||||
}";
|
||||
|
||||
Assert.AreEqual(expectedJson, json);
|
||||
|
||||
XmlNode node = JsonConvert.DeserializeXmlNode(json);
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
XmlWriter writer = XmlWriter.Create(sw, new XmlWriterSettings
|
||||
{
|
||||
Indent = true,
|
||||
OmitXmlDeclaration = true
|
||||
});
|
||||
node.WriteTo(writer);
|
||||
writer.Flush();
|
||||
|
||||
string xaml2 = sw.ToString();
|
||||
|
||||
string expectedXaml = @"<Grid xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"" xmlns:toolkit=""clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"" Style=""{StaticResource trimFormGrid}"" x:Name=""TrimObjectForm"">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width=""63*"" />
|
||||
<ColumnDefinition Width=""320*"" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions xmlns="""">
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
<RowDefinition />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding TypedTitle, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordTypedTitle"" Grid.Column=""1"" Grid.Row=""0"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding ExternalReference, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordExternalReference"" Grid.Column=""1"" Grid.Row=""1"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Author, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAuthor"" Grid.Column=""1"" Grid.Row=""4"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Container, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordContainer"" Grid.Column=""1"" Grid.Row=""5"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding IsEnclosed, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordIsEnclosed"" Grid.Column=""1"" Grid.Row=""6"" xmlns="""" />
|
||||
<TextBox Style=""{StaticResource trimFormGrid_TB}"" Text=""{Binding Assignee, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordAssignee"" Grid.Column=""1"" Grid.Row=""7"" xmlns="""" />
|
||||
<toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateCreated, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateCreated"" Grid.Column=""1"" Grid.Row=""2"" />
|
||||
<toolkit:DatePicker Style=""{StaticResource trimFormGrid_DP}"" Value=""{Binding DateDue, Converter={StaticResource trimPropertyConverter}}"" Name=""RecordDateDue"" Grid.Column=""1"" Grid.Row=""3"" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Title (Free Text Part)"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""0"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""External ID"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""1"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Date Created"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""2"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Date Due"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""3"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Author"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""4"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Container"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""5"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Enclosed?"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""6"" xmlns="""" />
|
||||
<TextBlock Grid.Column=""0"" Text=""Assignee"" Style=""{StaticResource trimFormGrid_LBL}"" Grid.Row=""7"" xmlns="""" />
|
||||
</Grid>";
|
||||
|
||||
Assert.AreEqual(expectedXaml, xaml2);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user