本文整理汇总了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);
}
}
}
示例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);
}