本文整理汇总了C#中YAXLib.YAXSerializer.Deserialize方法的典型用法代码示例。如果您正苦于以下问题:C# YAXSerializer.Deserialize方法的具体用法?C# YAXSerializer.Deserialize怎么用?C# YAXSerializer.Deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YAXLib.YAXSerializer
的用法示例。
在下文中一共展示了YAXSerializer.Deserialize方法的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: Read
protected Xwt.Widget Read(string Text)
{
YAXLib.YAXSerializer Y = new YAXSerializer(typeof(FrameRootNode), YAXExceptionHandlingPolicies.DoNotThrow);
FrameRootNode Target = (FrameRootNode)Y.Deserialize(Text);
this.Root = Target.Content.Makeup(this);
return Root;
}
示例3: GetAdaptor
public object GetAdaptor(string adaptorName, Type adaptorType, Stream sutFile = null)
{
if (adaptors.ContainsKey(adaptorName))
{
return adaptors[adaptorName];
}
var serializer = new YAXSerializer(adaptorType, YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Error, YAXSerializationOptions.DontSerializeNullObjects);
AdaptorImpl adaptor = null;
try
{
string sutXml = null;
if (sutFile != null)
{
var stramReader = new StreamReader(sutFile);
sutXml = stramReader.ReadToEnd();
}
else
{
sutXml = File.ReadAllText(SutManager.CurrentSut());
}
adaptor = (AdaptorImpl)serializer.Deserialize(sutXml);
}
catch (YAXBadlyFormedXML e)
{
report.Report("Failed to read sut file", e);
return null;
}
adaptors.Add(adaptorName, adaptor);
adaptor.Init();
return adaptor;
}
示例4: 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));
}
示例5: 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));
}
示例6: DeserializeDataFromStream
/// <summary>
/// Deserializes graph data from a stream
/// </summary>
/// <param name="stream">The stream</param>
/// <returns>The graph data</returns>
public static List<GraphSerializationData> DeserializeDataFromStream(Stream stream)
{
var deserializer = new YAXSerializer(typeof(List<GraphSerializationData>));
using (var textReader = new StreamReader(stream))
{
return (List<GraphSerializationData>)deserializer.Deserialize(textReader);
}
}
示例7: Parse
public static ProjectBuildDefinition Parse(string xml)
{
var yaxSer = new YAXSerializer(typeof(ProjectBuildDefinition),
YAXExceptionHandlingPolicies.DoNotThrow,
YAXExceptionTypes.Ignore,
YAXSerializationOptions.DontSerializeNullObjects);
return yaxSer.Deserialize(xml) as ProjectBuildDefinition;
}
示例8: 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);
}
}
示例9: AttributeForKeyInDictionaryPropertyTest
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);
}
示例10: TestSingleMin
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);
}
}
示例11: TestSerializingNDeserializingNullKnownTypes
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);
}
}
示例12: MultiLevelMemberAndClassDifferentNamespacesDeserializationTest
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));
}
示例13: MoreComplexBookTwoResumedDeserializationTest
public void MoreComplexBookTwoResumedDeserializationTest()
{
string result =
@"<MoreComplexBook2 Author_s_Name=""Tom Archer"">
<Title>Inside C#</Title>
<PublishYear>2002</PublishYear>
<Price>30.5</Price>
</MoreComplexBook2>";
MoreComplexBook2 book = new MoreComplexBook2();
book.Author = new Author()
{
Name = null,
Age = 40
};
string initialToString = book.ToString();
YAXSerializer serializer = new YAXSerializer(typeof(MoreComplexBook2), YAXExceptionHandlingPolicies.DoNotThrow, YAXExceptionTypes.Warning, YAXSerializationOptions.SerializeNullObjects);
serializer.SetDeserializationBaseObject(book);
MoreComplexBook2 bookResult = (MoreComplexBook2)serializer.Deserialize(result);
Assert.AreNotEqual(bookResult.ToString(), initialToString);
}
示例14: YAXSerializer
public void InfiniteLoopCausedBySerializingCalculatedPropertiesCanBePreventedBySettingDontSerializePropertiesWithNoSetter()
{
var ser = new YAXSerializer(typeof(CalculatedPropertiesCanCauseInfiniteLoop), YAXSerializationOptions.DontSerializePropertiesWithNoSetter);
string result = ser.Serialize(CalculatedPropertiesCanCauseInfiniteLoop.GetSampleInstance());
var deserialzedInstance = ser.Deserialize(result) as CalculatedPropertiesCanCauseInfiniteLoop;
Assert.IsNotNull(deserialzedInstance);
}
示例15: PolymorphicSerializationThroughListWhichMayContainYaxlibNamespaceTest
public void PolymorphicSerializationThroughListWhichMayContainYaxlibNamespaceTest()
{
var lst = new List<object> { 1, 2, 3 };
var ser = new YAXSerializer(typeof(object));
string xmlResult = ser.Serialize(lst);
const string expectedResult =
@"<Object xmlns:yaxlib=""http://www.sinairv.com/yaxlib/"" yaxlib:realtype=""System.Collections.Generic.List`1[[System.Object, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]"">
<Int32 yaxlib:realtype=""System.Int32"">1</Int32>
<Int32 yaxlib:realtype=""System.Int32"">2</Int32>
<Int32 yaxlib:realtype=""System.Int32"">3</Int32>
</Object>";
Assert.That(xmlResult.StripTypeAssemblyVersion(), Is.EqualTo(expectedResult.StripTypeAssemblyVersion()));
var desObj = ser.Deserialize(xmlResult);
Assert.That(desObj.GetType(), Is.EqualTo(lst.GetType()));
var desLst = desObj as List<object>;
Assert.That(lst, Has.Count.EqualTo(desLst.Count));
Assert.That(lst, Is.EquivalentTo(desLst));
}