public void AnotherArraySampleTest() { const string result = @"<!-- This example shows usage of jagged multi-dimensional arrays --> <AnotherArraySample xmlns:yaxlib=""http://www.sinairv.com/yaxlib/""> <Array1> <Array2OfInt32 yaxlib:dims=""2,3""> <Int32>1</Int32> <Int32>1</Int32> <Int32>1</Int32> <Int32>1</Int32> <Int32>2</Int32> <Int32>3</Int32> </Array2OfInt32> <Array2OfInt32 yaxlib:dims=""3,2""> <Int32>3</Int32> <Int32>3</Int32> <Int32>3</Int32> <Int32>4</Int32> <Int32>3</Int32> <Int32>5</Int32> </Array2OfInt32> </Array1> </AnotherArraySample>"; var serializer = new YAXSerializer(typeof(AnotherArraySample), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(AnotherArraySample.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public void CanUseTheDefaultNamespace() { var ser = new YAXSerializer(typeof(YAXLibMetadataOverriding)); ser.YaxLibNamespacePrefix = ""; ser.YaxLibNamespaceUri = "http://namespace.org/sample"; ser.DimentionsAttributeName = "dm"; ser.RealTypeAttributeName = "type"; var sampleInstance = YAXLibMetadataOverriding.GetSampleInstance(); string result = ser.Serialize(sampleInstance); string expected = @"<YAXLibMetadataOverriding xmlns=""http://namespace.org/sample""> <IntArray dm=""2,3""> <Int32>1</Int32> <Int32>2</Int32> <Int32>3</Int32> <Int32>2</Int32> <Int32>3</Int32> <Int32>4</Int32> </IntArray> <Obj type=""System.String"">Hello, World!</Obj> </YAXLibMetadataOverriding>"; Assert.That(result, Is.EqualTo(expected)); var desObj = (YAXLibMetadataOverriding)ser.Deserialize(expected); Assert.That(desObj.Obj.ToString(), Is.EqualTo(sampleInstance.Obj.ToString())); Assert.That(desObj.IntArray.Length, Is.EqualTo(sampleInstance.IntArray.Length)); }
public static void Serialize(List<ObjectEffect> effects) { foreach (var effect in effects) { YAXSerializer serializer = new YAXSerializer(effect.GetType()); string contents = serializer.Serialize(effect); } }
public static void SavePlanDesign(PlanDesign design, string filePath, out string xmlResult) { YAXSerializer serializer = new YAXSerializer(typeof(PlanDesign)); xmlResult = serializer.Serialize(design); File.WriteAllText(filePath, xmlResult); MyLog.Writer.WriteLine(MyLogLevel.INFO, "School project saved to: " + filePath); }
public void CollectionNamespaceForAllItemsDeserializationTest() { var serializer = new YAXSerializer(typeof(CellPhone_CollectionNamespaceForAllItems), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(CellPhone_CollectionNamespaceForAllItems.GetSampleInstance()); var deserialized = serializer.Deserialize(got) as CellPhone_CollectionNamespaceForAllItems; Assert.That(deserialized, Is.Not.Null); Assert.That(serializer.ParsingErrors, Has.Count.EqualTo(0)); }
public void AttributeWithDefaultNamespaceDeserializationTest() { var serializer = new YAXSerializer(typeof(AttributeWithNamespace), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(AttributeWithNamespace.GetSampleInstance()); var deserialized = serializer.Deserialize(got) as AttributeWithNamespace; Assert.That(deserialized, Is.Not.Null); Assert.That(serializer.ParsingErrors, Has.Count.EqualTo(0)); }
/// <summary> /// Serializes graph data list to a stream /// </summary> /// <param name="stream">The destination stream</param> /// <param name="modelsList">The graph data</param> public static void SerializeDataToStream(Stream stream, List<GraphSerializationData> modelsList) { var serializer = new YAXSerializer(typeof(List<GraphSerializationData>)); using (var textWriter = new StreamWriter(stream)) { serializer.Serialize(modelsList, textWriter); textWriter.Flush(); } }
private static void SerializeNode(XmlWriter wr, MyVertex vr) { wr.WriteAttributeString("type", vr.Job.GetType().FullName); var serializer = new YAXLib.YAXSerializer(vr.Job.GetType(), YAXSerializationOptions.DontSerializeNullObjects); var result = serializer.Serialize(vr); wr.WriteRaw(result); }
public void AttributeNamespaceSerializationTest() { const string result = "<AttributeNamespaceSample xmlns:ns=\"http://namespaces.org/ns\" xmlns=\"http://namespaces.org/default\">" + @" <Attribs " + "attrib=\"value\" ns:attrib2=\"value2\"" + @" /> </AttributeNamespaceSample>"; var serializer = new YAXSerializer(typeof(AttributeNamespaceSample), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(AttributeNamespaceSample.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public void AudioSampleTest() { const string result = @"<AudioSample> <Audio FileName=""filesname.jpg"">base64</Audio> <Image FileName=""filesname.jpg"">base64</Image> </AudioSample>"; var serializer = new YAXSerializer(typeof(AudioSample), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(AudioSample.GetSampleInstance()); Assert.AreEqual(result, got); }
public void AttributeWithDefaultNamespaceAsMemberSerializationTest() { const string result = @"<AttributeWithNamespaceAsMember xmlns:w=""http://example.com/namespace""> <w:Member w:name=""Arial"" /> </AttributeWithNamespaceAsMember>"; var serializer = new YAXSerializer(typeof(AttributeWithNamespaceAsMember), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(AttributeWithNamespaceAsMember.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public static string ParseAndRegenerateXml(string xml) { var project = Parse(xml); var yaxSer = new YAXSerializer(typeof(ProjectBuildDefinition), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Ignore, YAXSerializationOptions.DontSerializeNullObjects); return yaxSer.Serialize(project); }
public void AttributeForClassTest() { var ser = new YAXSerializer(typeof(AttributeContainerSample)); string result = ser.Serialize(AttributeContainerSample.GetSampleInstance()); const string expectedResult = @"<container> <range from=""1"" to=""3"" /> </container>"; Assert.That(expectedResult, Is.EqualTo(result)); }
public void TestDoubleMax() { try { var ser = new YAXSerializer(typeof (double), YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); double d = 0.55; var xml = ser.Serialize(d); var deseredInstance = ser.Deserialize(xml); Assert.AreEqual(d, deseredInstance); d = Double.MaxValue; xml = ser.Serialize(d); deseredInstance = ser.Deserialize(xml); // Causes a System.OverflowException {"Value was either too large or too small for a Double."} Assert.AreEqual(d, deseredInstance); } catch (Exception ex) { Assert.Fail("No exception should have been throwned, but received:" + Environment.NewLine + ex); } }
private static void TryYax() { var obj = CreateFakeObject(); obj.SetValues(); var serializer = new YAXSerializer(typeof(Parameters), YAXExceptionHandlingPolicies.DoNotThrow,YAXExceptionTypes.Error, YAXSerializationOptions.DontSerializeCyclingReferences|YAXSerializationOptions.DontSerializeNullObjects|YAXSerializationOptions.DontSerializePropertiesWithNoSetter); var someString = serializer.Serialize(obj); File.WriteAllText("yax.xml", someString); var back = serializer.DeserializeFromFile("yax.xml"); }
public void RectangleSerializationTest() { const string result = @"<RectangleDynamicKnownTypeSample> <Rect> <Left>10</Left> <Top>20</Top> <Width>30</Width> <Height>40</Height> </Rect> </RectangleDynamicKnownTypeSample>"; var serializer = new YAXSerializer(typeof(RectangleDynamicKnownTypeSample), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(RectangleDynamicKnownTypeSample.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public void AttributeForKeyInDictionaryPropertyTest() { var container = DictionaryContainerSample.GetSampleInstance(); var ser = new YAXSerializer(typeof(DictionaryContainerSample)); string input = ser.Serialize(container); var deserializedContainer = (DictionaryContainerSample)ser.Deserialize(input); Assert.IsNotNull(deserializedContainer.Items); Assert.IsTrue(deserializedContainer.Items.Count == container.Items.Count, "Expected Count: {0}. Actual Count: {1}", container.Items.Count, deserializedContainer.Items.Count); }
public void AttributeForKeyInDictionaryPropertyTest() { var container = DictionaryContainerSample.GetSampleInstance(); var ser = new YAXSerializer(typeof(DictionaryContainerSample)); string result = ser.Serialize(container); const string expectedResult = @"<container xmlns=""http://example.com/""> <items> <item key=""key1"">00000001-0002-0003-0405-060708090a0b</item> <item key=""key2"">1234</item> </items> </container>"; Assert.AreEqual(expectedResult, result); }
public void TestSingleMin() { try { var ser = new YAXSerializer(typeof (float), YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); float f = Single.MinValue; var xml = ser.Serialize(f); var deseredInstance = ser.Deserialize(xml); Assert.AreEqual(f, deseredInstance); } catch (Exception ex) { Assert.Fail("No exception should have been throwned, but received:" + Environment.NewLine + ex); } }
public void DataSetAndDataTableSerializationTest() { const string result = @"<DataSetAndDataTableKnownTypeSample> <TheDataTable> <NewDataSet> <TableName xmlns=""http://tableNs/""> <Col1>1</Col1> <Col2>2</Col2> <Col3>3</Col3> </TableName> <TableName xmlns=""http://tableNs/""> <Col1>y</Col1> <Col2>4</Col2> <Col3>n</Col3> </TableName> </NewDataSet> </TheDataTable> <TheDataSet> <MyDataSet> <Table1> <Cl1>num1</Cl1> <Cl2>34</Cl2> </Table1> <Table1> <Cl1>num2</Cl1> <Cl2>54</Cl2> </Table1> <Table2> <C1>one</C1> <C2>1</C2> <C3>1.5</C3> </Table2> <Table2> <C1>two</C1> <C2>2</C2> <C3>2.5</C3> </Table2> </MyDataSet> </TheDataSet> </DataSetAndDataTableKnownTypeSample>"; var serializer = new YAXSerializer(typeof(DataSetAndDataTableKnownTypeSample), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(DataSetAndDataTableKnownTypeSample.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public void BasicTypeSerializationTest() { var objs = new object[] {123, 654.321, "SomeString", 24234L}; var types = new [] {typeof (int), typeof (double), typeof (string), typeof (long)}; var serializedResults = new[] { "<Int32>123</Int32>", "<Double>654.321</Double>", "<String>SomeString</String>", "<Int64>24234</Int64>" }; for (int i = 0; i < objs.Length; i++) { var serializer = new YAXSerializer(objs[i].GetType()); var got = serializer.Serialize(objs[i]); Assert.AreEqual(serializedResults[i], got); var deser = new YAXSerializer(types[i]); var obj = deser.Deserialize(got); Assert.AreEqual(obj, objs[i]); } }
public void CollectionNamespaceForAllItemsSerializationTest() { const string result = @"<MobilePhone xmlns:app=""http://namespace.org/apps"" xmlns:cls=""http://namespace.org/colorCol"" xmlns:mdls=""http://namespace.org/modelCol"" xmlns:p1=""http://namespace.org/appName"" xmlns:p2=""http://namespace.org/color""> <DeviceBrand>Samsung Galaxy Nexus</DeviceBrand> <OS>Android</OS> <p1:AppName>Google Map</p1:AppName> <p1:AppName>Google+</p1:AppName> <p1:AppName>Google Play</p1:AppName> <cls:AvailableColors> <p2:TheColor>Red</p2:TheColor> <p2:TheColor>Black</p2:TheColor> <p2:TheColor>White</p2:TheColor> </cls:AvailableColors> <mdls:AvailableModels>S1,MII,SXi,NoneSense</mdls:AvailableModels> </MobilePhone>"; var serializer = new YAXSerializer(typeof(CellPhone_CollectionNamespaceForAllItems), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(CellPhone_CollectionNamespaceForAllItems.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public void TestSerializingNDeserializingNullKnownTypes() { var inst = ClassContainingXElement.GetSampleInstance(); inst.TheElement = null; inst.TheAttribute = null; var ser = new YAXSerializer(typeof (ClassContainingXElement), YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); try { var xml = ser.Serialize(inst); var deseredInstance = ser.Deserialize(xml); Assert.AreEqual(inst.ToString(), deseredInstance.ToString()); } catch (Exception ex) { Assert.Fail("No exception should have been throwned, but received:\r\n" + ex); } }
private void OnSerialize(bool saveToFile) { object selItem = lstSampleClasses.SelectedItem; if (selItem == null || !(selItem is ClassInfoListItem)) return; string fileName = null; if (saveToFile) { if (DialogResult.OK != saveFileDialog1.ShowDialog()) return; fileName = saveFileDialog1.FileName; } ClassInfoListItem info = selItem as ClassInfoListItem; YAXExceptionTypes defaultExType = GetSelectedDefaultExceptionType(); YAXExceptionHandlingPolicies exPolicy = GetSelectedExceptionHandlingPolicy(); YAXSerializationOptions serOption = GetSelectedSerializationOption(); try { YAXSerializer serializer = new YAXSerializer(info.ClassType, exPolicy, defaultExType, serOption); serializer.MaxRecursion = Convert.ToInt32(numMaxRecursion.Value); if (saveToFile) serializer.SerializeToFile(info.SampleObject, fileName); else rtbXMLOutput.Text = serializer.Serialize(info.SampleObject); rtbParsingErrors.Text = serializer.ParsingErrors.ToString(); } catch (YAXException ex) { MessageBox.Show("YAXException handled:\r\n\r\n" + ex.ToString()); } catch (Exception ex) { MessageBox.Show("Other Exception handled:\r\n\r\n" + ex.ToString()); } }
public void YAXNamespaceOverridesImplicitNamespaceSerializationTest() { const string result = @"<CellPhone_YAXNamespaceOverridesImplicitNamespace xmlns:p1=""http://namespace.org/explicitBrand"" xmlns:p2=""http://namespace.org/os""> <p1:Brand>Samsung Galaxy S II</p1:Brand> <p2:OperatingSystem>Android 2</p2:OperatingSystem> </CellPhone_YAXNamespaceOverridesImplicitNamespace>"; var serializer = new YAXSerializer(typeof(CellPhone_YAXNamespaceOverridesImplicitNamespace), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(CellPhone_YAXNamespaceOverridesImplicitNamespace.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public void SingleNamespaceSerializationTest() { const string result = @"<!-- This example shows usage of a custom default namespace --> " + "<SingleNamespaceSample xmlns=\"http://namespaces.org/default\">" + @" <StringItem>This is a test string</StringItem> <IntItem>10</IntItem> </SingleNamespaceSample>"; var serializer = new YAXSerializer(typeof(SingleNamespaceSample), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(SingleNamespaceSample.GetInstance()); Assert.That(got, Is.EqualTo(result)); }
public void SingleNamespaceDeserializationTest() { var serializer = new YAXSerializer(typeof(SingleNamespaceSample), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string serialized = serializer.Serialize(SingleNamespaceSample.GetInstance()); var deserialized = serializer.Deserialize(serialized) as SingleNamespaceSample; Assert.That(deserialized, Is.Not.Null); Assert.That(serializer.ParsingErrors, Has.Count.EqualTo(0)); }
public void MutlilevelObjectsWithNamespacesSerializationTest() { const string result = @"<MutlilevelObjectsWithNamespaces xmlns:ch1=""http://namespace.org/ch1"" xmlns:ch2=""http://namespace.org/ch2"" xmlns=""http://namespace.org/default""> <Parent1> <ch1:Child1 ch2:Value3=""Value3""> <ch1:Field1>Field1</ch1:Field1> <ch1:Field2>Field2</ch1:Field2> <ch2:Value1>Value1</ch2:Value1> <ch2:Value2>Value2</ch2:Value2> </ch1:Child1> </Parent1> <Parent2> <ch2:Child2> <ch2:Value4>Value4</ch2:Value4> </ch2:Child2> </Parent2> </MutlilevelObjectsWithNamespaces>"; var serializer = new YAXSerializer(typeof(MutlilevelObjectsWithNamespaces), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(MutlilevelObjectsWithNamespaces.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public void MultipleNamespaceSerializationTest() { const string result = @"<!-- This example shows usage of a number of custom namespaces --> <ns1:MultipleNamespaceSample xmlns:ns1=""http://namespaces.org/ns1"" xmlns:ns2=""http://namespaces.org/ns2"" xmlns:ns3=""http://namespaces.org/ns3""> <ns1:BoolItem>True</ns1:BoolItem> <ns2:StringItem>This is a test string</ns2:StringItem> <ns3:IntItem>10</ns3:IntItem> </ns1:MultipleNamespaceSample>"; var serializer = new YAXSerializer(typeof(MultipleNamespaceSample), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(MultipleNamespaceSample.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public void MultiLevelMemberAndClassDifferentNamespacesSerializationTest() { const string result = @"<CellPhone_MultiLevelMemberAndClassDifferentNamespaces xmlns:x1=""http://namespace.org/x1"" xmlns=""http://namespace.org/nsmain""> <Level1> <Level2> <x1:TheName>HTC</x1:TheName> </Level2> </Level1> <OS>Windows Phone 8</OS> </CellPhone_MultiLevelMemberAndClassDifferentNamespaces>"; var serializer = new YAXSerializer(typeof(CellPhone_MultiLevelMemberAndClassDifferentNamespaces), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(CellPhone_MultiLevelMemberAndClassDifferentNamespaces.GetSampleInstance()); Assert.That(got, Is.EqualTo(result)); }
public void MultiLevelMemberAndClassDifferentNamespacesDeserializationTest() { var serializer = new YAXSerializer(typeof(CellPhone_MultiLevelMemberAndClassDifferentNamespaces), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects); string got = serializer.Serialize(CellPhone_MultiLevelMemberAndClassDifferentNamespaces.GetSampleInstance()); var deserialized = serializer.Deserialize(got) as CellPhone_MultiLevelMemberAndClassDifferentNamespaces; Assert.That(deserialized, Is.Not.Null); Assert.That(serializer.ParsingErrors, Has.Count.EqualTo(0)); }