本文整理汇总了C#中YAXLib.YAXSerializer.SerializeToXDocument方法的典型用法代码示例。如果您正苦于以下问题:C# YAXSerializer.SerializeToXDocument方法的具体用法?C# YAXSerializer.SerializeToXDocument怎么用?C# YAXSerializer.SerializeToXDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YAXLib.YAXSerializer
的用法示例。
在下文中一共展示了YAXSerializer.SerializeToXDocument方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SerializeBase
/// <summary>
/// One of the base methods that perform the whole job of serialization.
/// </summary>
/// <param name="obj">The object to be serialized</param>
/// <returns>an instance of <c>XElement</c> which contains the result of
/// serialization of the specified object</returns>
private XElement SerializeBase(object obj)
{
if (!m_type.IsInstanceOfType(obj))
{
throw new YAXObjectTypeMismatch(m_type, obj.GetType());
}
// to serialize stand-alone collection or dictionary objects
if (m_udtWrapper.IsTreatedAsDictionary)
{
var elemResult = MakeDictionaryElement(null, m_udtWrapper.Alias, obj,
m_udtWrapper.DictionaryAttributeInstance, m_udtWrapper.CollectionAttributeInstance);
if (m_udtWrapper.PreservesWhitespace)
XMLUtils.AddPreserveSpaceAttribute(elemResult);
return elemResult;
}
else if (m_udtWrapper.IsTreatedAsCollection)
{
var elemResult = MakeCollectionElement(null, m_udtWrapper.Alias, obj, null, null);
if (m_udtWrapper.PreservesWhitespace)
XMLUtils.AddPreserveSpaceAttribute(elemResult);
return elemResult;
}
else if(ReflectionUtils.IsBasicType(m_udtWrapper.UnderlyingType))
{
bool dummyAlreadyAdded;
var elemResult = MakeBaseElement(null, m_udtWrapper.Alias, obj, out dummyAlreadyAdded);
if (m_udtWrapper.PreservesWhitespace)
XMLUtils.AddPreserveSpaceAttribute(elemResult);
return elemResult;
}
else if(!m_udtWrapper.UnderlyingType.EqualsOrIsNullableOf(obj.GetType()))
{
// this block of code runs if the serializer is instantiated with a
// another base value such as System.Object but is provided with an
// object of its child
var ser = new YAXSerializer(obj.GetType(), m_exceptionPolicy,
m_defaultExceptionType, m_serializationOption);
ser.SetNamespaceToOverrideEmptyNamespace(TypeNamespace);
//ser.SetBaseElement(insertionLocation);
var xdoc = ser.SerializeToXDocument(obj);
var elem = xdoc.Root;
ImportNamespaces(ser);
m_parsingErrors.AddRange(ser.ParsingErrors);
elem.Name = m_udtWrapper.Alias;
elem.AddAttributeNamespaceSafe(m_yaxLibNamespaceUri + m_trueTypeAttrName, obj.GetType().FullName);
RegisterYaxLibNamespace();
AddNamespacesToElement(elem);
return elem;
}
else
{
return SerializeBase(obj, m_udtWrapper.Alias);
}
}
示例2: CreateXml
/// <summary>
/// Create valid TelApi XML response
/// </summary>
/// <returns></returns>
public string CreateXml()
{
var serializer = new YAXSerializer(typeof(Response), YAXExceptionHandlingPolicies.ThrowErrorsOnly, YAXExceptionTypes.Error, YAXSerializationOptions.DontSerializeNullObjects);
var result = serializer.SerializeToXDocument(this);
return ModifyXML(result);
}