当前位置: 首页>>代码示例>>C#>>正文


C# YAXSerializer.Deserialize方法代码示例

本文整理汇总了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));
        }
开发者ID:silwol,项目名称:YAXLib,代码行数:31,代码来源:OverridingYAXLibMetadataTests.cs

示例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;
 }
开发者ID:ksigne,项目名称:xwt-extensions,代码行数:7,代码来源:FrameExt.cs

示例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;
        }
开发者ID:Top-Q,项目名称:TFS-automation-testing-framework,代码行数:34,代码来源:AdaptorsManager.cs

示例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));
 }
开发者ID:miloszkukla,项目名称:YAXLib,代码行数:8,代码来源:NamespaceTest.cs

示例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));
 }
开发者ID:silwol,项目名称:YAXLib,代码行数:8,代码来源:NamespaceTest.cs

示例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);
            }
        }
开发者ID:aliaspilote,项目名称:TX52,代码行数:13,代码来源:FileServiceProviderWPF.cs

示例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;
        }
开发者ID:sschocke,项目名称:BrainSimulator,代码行数:9,代码来源:CsprojParser.cs

示例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);
            }
        }
开发者ID:miloszkukla,项目名称:YAXLib,代码行数:22,代码来源:NumericMinMaxTests.cs

示例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);
        }
开发者ID:sinairv,项目名称:YAXLib,代码行数:16,代码来源:DeserializationTest.cs

示例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);
     }
 }
开发者ID:miloszkukla,项目名称:YAXLib,代码行数:16,代码来源:NumericMinMaxTests.cs

示例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);
            }
        }
开发者ID:SPARTAN563,项目名称:YAXLib,代码行数:20,代码来源:KnownTypeTests.cs

示例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));
 }
开发者ID:miloszkukla,项目名称:YAXLib,代码行数:8,代码来源:NamespaceTest.cs

示例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);
        }
开发者ID:sinairv,项目名称:YAXLib,代码行数:22,代码来源:DeserializationTest.cs

示例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);
        }
开发者ID:sinairv,项目名称:YAXLib,代码行数:8,代码来源:DeserializationTest.cs

示例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));
        }
开发者ID:sschocke,项目名称:BrainSimulator,代码行数:20,代码来源:SerializationTest.cs


注:本文中的YAXLib.YAXSerializer.Deserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。