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


C# YAXSerializer.SetDeserializationBaseObject方法代码示例

本文整理汇总了C#中YAXLib.YAXSerializer.SetDeserializationBaseObject方法的典型用法代码示例。如果您正苦于以下问题:C# YAXSerializer.SetDeserializationBaseObject方法的具体用法?C# YAXSerializer.SetDeserializationBaseObject怎么用?C# YAXSerializer.SetDeserializationBaseObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在YAXLib.YAXSerializer的用法示例。


在下文中一共展示了YAXSerializer.SetDeserializationBaseObject方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RetreiveElementValue


//.........这里部分代码省略.........
                }
            }
            else if (memberType == typeof(string))
            {
                if (String.IsNullOrEmpty(elemValue) && xelemValue != null)
                {
                    if (xelemValue.IsEmpty)
                        elemValue = null;
                    else
                        elemValue = String.Empty;
                }

                try
                {
                    member.SetValue(o, elemValue);
                }
                catch
                {
                    this.OnExceptionOccurred(new YAXPropertyCannotBeAssignedTo(member.Alias.LocalName), this.m_defaultExceptionType);
                }
            }
            else if (ReflectionUtils.IsBasicType(memberType))
            {
                object convertedObj;

                if (ReflectionUtils.IsNullable(memberType) && String.IsNullOrEmpty(elemValue))
                {
                    convertedObj = member.DefaultValue;
                }
                else
                {
                    convertedObj = ReflectionUtils.ConvertBasicType(elemValue, memberType);
                }

                try
                {
                    try
                    {
                        member.SetValue(o, convertedObj);
                    }
                    catch
                    {
                        this.OnExceptionOccurred(new YAXPropertyCannotBeAssignedTo(member.Alias.LocalName), m_defaultExceptionType);
                    }
                }
                catch (Exception ex)
                {
                    if (ex is YAXException)
                    {
                        throw;
                    }

                    this.OnExceptionOccurred(new YAXBadlyFormedInput(member.Alias.LocalName, elemValue), member.TreatErrorsAs);

                    try
                    {
                        member.SetValue(o, member.DefaultValue);
                    }
                    catch
                    {
                        this.OnExceptionOccurred(new YAXDefaultValueCannotBeAssigned(member.Alias.LocalName, member.DefaultValue), m_defaultExceptionType);
                    }
                }
            }
            else if (member.IsTreatedAsDictionary && member.DictionaryAttributeInstance != null)
            {
                DeserializeTaggedDictionaryMember(o, member, xelemValue);
            }
            else if (member.IsTreatedAsCollection)
            {
                DeserializeCollectionMember(o, member, memberType, elemValue, xelemValue);
            }
            else
            {
                var ser = new YAXSerializer(memberType, m_exceptionPolicy, m_defaultExceptionType, m_serializationOption);
                ser.SetNamespaceToOverrideEmptyNamespace(
                    member.Namespace.
                        IfEmptyThen(this.TypeNamespace).
                        IfEmptyThenNone());

                ser.IsCraetedToDeserializeANonCollectionMember = !(member.IsTreatedAsDictionary || member.IsTreatedAsCollection);

                if (m_desObject != null) // i.e. it is in resuming mode
                {
                    ser.SetDeserializationBaseObject(member.GetValue(o));
                }

                object convertedObj = ser.DeserializeBase(xelemValue);
                m_parsingErrors.AddRange(ser.ParsingErrors);

                try
                {
                    member.SetValue(o, convertedObj);
                }
                catch
                {
                    this.OnExceptionOccurred(new YAXPropertyCannotBeAssignedTo(member.Alias.LocalName), this.m_defaultExceptionType);
                }
            }
        }
开发者ID:silwol,项目名称:YAXLib,代码行数:101,代码来源:YAXSerializer.cs

示例2: 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


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