本文整理汇总了C#中XmlObjectSerializerWriteContext.WriteNull方法的典型用法代码示例。如果您正苦于以下问题:C# XmlObjectSerializerWriteContext.WriteNull方法的具体用法?C# XmlObjectSerializerWriteContext.WriteNull怎么用?C# XmlObjectSerializerWriteContext.WriteNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XmlObjectSerializerWriteContext
的用法示例。
在下文中一共展示了XmlObjectSerializerWriteContext.WriteNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReflectionWriteValue
public void ReflectionWriteValue(XmlWriterDelegator xmlWriter, XmlObjectSerializerWriteContext context, Type type, object value, bool writeXsiType, PrimitiveDataContract primitiveContractForParamType)
{
Type memberType = type;
object memberValue = value;
TypeInfo memberTypeInfo = memberType.GetTypeInfo();
bool originValueIsNullableOfT = (memberTypeInfo.IsGenericType && memberType.GetGenericTypeDefinition() == Globals.TypeOfNullable);
if (memberTypeInfo.IsValueType && !originValueIsNullableOfT)
{
PrimitiveDataContract primitiveContract = primitiveContractForParamType;
if (primitiveContract != null && !writeXsiType)
{
primitiveContract.WriteXmlValue(xmlWriter, memberValue, context);
}
else
{
ReflectionInternalSerialize(xmlWriter, context, memberValue, memberValue.GetType().TypeHandle.Equals(memberType.TypeHandle), writeXsiType, memberType);
}
}
else
{
if (originValueIsNullableOfT)
{
if (memberValue == null)
{
memberType = Nullable.GetUnderlyingType(memberType);
}
else
{
MethodInfo getValue = memberType.GetMethod("get_Value", Array.Empty<Type>());
memberValue = getValue.Invoke(memberValue, Array.Empty<object>());
memberType = memberValue.GetType();
}
}
if (memberValue == null)
{
context.WriteNull(xmlWriter, memberType, DataContract.IsTypeSerializable(memberType));
}
else
{
PrimitiveDataContract primitiveContract = originValueIsNullableOfT ? PrimitiveDataContract.GetPrimitiveDataContract(memberType) : primitiveContractForParamType;
if (primitiveContract != null && primitiveContract.UnderlyingType != Globals.TypeOfObject && !writeXsiType)
{
primitiveContract.WriteXmlValue(xmlWriter, memberValue, context);
}
else
{
if (memberValue == null &&
(memberType == Globals.TypeOfObject
|| (originValueIsNullableOfT && memberType.GetTypeInfo().IsValueType)))
{
context.WriteNull(xmlWriter, memberType, DataContract.IsTypeSerializable(memberType));
}
else
{
ReflectionInternalSerialize(xmlWriter, context, memberValue, memberValue.GetType().TypeHandle.Equals(memberType.TypeHandle), writeXsiType, memberType, originValueIsNullableOfT);
}
}
}
}
}