本文整理汇总了C#中YAXLib.YAXSerializer.Serialize方法的典型用法代码示例。如果您正苦于以下问题:C# YAXSerializer.Serialize方法的具体用法?C# YAXSerializer.Serialize怎么用?C# YAXSerializer.Serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YAXLib.YAXSerializer
的用法示例。
在下文中一共展示了YAXSerializer.Serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanUseTheDefaultNamespace
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));
}
示例2: AnotherArraySampleTest
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));
}
示例3: CollectionNamespaceForAllItemsDeserializationTest
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));
}
示例4: Serialize
public static void Serialize(List<ObjectEffect> effects)
{
foreach (var effect in effects)
{
YAXSerializer serializer = new YAXSerializer(effect.GetType());
string contents = serializer.Serialize(effect);
}
}
示例5: AttributeWithDefaultNamespaceDeserializationTest
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));
}
示例6: SavePlanDesign
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);
}
示例7: SerializeDataToStream
/// <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();
}
}
示例8: AttributeNamespaceSerializationTest
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));
}
示例9: AttributeWithDefaultNamespaceAsMemberSerializationTest
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));
}
示例10: AudioSampleTest
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);
}
示例11: ParseAndRegenerateXml
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);
}
示例12: AttributeForClassTest
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));
}
示例13: TestDoubleMax
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);
}
}
示例14: TryYax
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");
}
示例15: RectangleSerializationTest
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));
}