本文整理汇总了C#中System.Runtime.Serialization.XmlWriterDelegator类的典型用法代码示例。如果您正苦于以下问题:C# XmlWriterDelegator类的具体用法?C# XmlWriterDelegator怎么用?C# XmlWriterDelegator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlWriterDelegator类属于System.Runtime.Serialization命名空间,在下文中一共展示了XmlWriterDelegator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReflectionWriteMembers
internal int ReflectionWriteMembers(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract, ClassDataContract derivedMostClassContract)
{
int memberCount = (classContract.BaseContract == null) ? 0 :
ReflectionWriteMembers(xmlWriter, obj, context, classContract.BaseContract, derivedMostClassContract);
Type classType = classContract.UnadaptedClassType;
XmlDictionaryString[] memberNames = classContract.MemberNames;
XmlDictionaryString ns = classContract.Namespace;
context.IncrementItemCount(classContract.Members.Count);
for (int i = 0; i < classContract.Members.Count; i++, memberCount++)
{
DataMember member = classContract.Members[i];
Type memberType = member.MemberType;
if (member.IsGetOnlyCollection)
{
context.StoreIsGetOnlyCollection();
}
bool writeXsiType = CheckIfMemberHasConflict(member, classContract, derivedMostClassContract);
MemberInfo memberInfo = member.MemberInfo;
object memberValue = ReflectionGetMemberValue(obj, memberInfo);
if (writeXsiType || !ReflectionTryWritePrimitive(xmlWriter, context, memberType, memberValue, member.MemberInfo, null /*arrayItemIndex*/, ns, memberNames[i] /*nameLocal*/, i + _childElementIndex))
{
ReflectionWriteStartElement(memberType, ns, ns.Value, member.Name, 0);
if (classContract.ChildElementNamespaces[i + _childElementIndex] != null)
{
var nsChildElement = classContract.ChildElementNamespaces[i + _childElementIndex];
_arg0XmlWriter.WriteNamespaceDecl(nsChildElement);
}
ReflectionWriteValue(memberType, memberValue, writeXsiType);
ReflectionWriteEndElement();
}
}
return 0;
}
示例2: SerializeWithXsiType
protected override void SerializeWithXsiType(XmlWriterDelegator xmlWriter, object obj, RuntimeTypeHandle objectTypeHandle, Type objectType, int declaredTypeID, RuntimeTypeHandle declaredTypeHandle, Type declaredType)
{
DataContract dataContract;
bool verifyKnownType = false;
bool isInterface = declaredType.IsInterface;
if (isInterface && CollectionDataContract.IsCollectionInterface(declaredType))
{
dataContract = this.GetDataContract(declaredTypeHandle, declaredType);
}
else if (declaredType.IsArray)
{
dataContract = this.GetDataContract(declaredTypeHandle, declaredType);
}
else
{
dataContract = this.GetDataContract(objectTypeHandle, objectType);
DataContract declaredContract = (declaredTypeID >= 0) ? this.GetDataContract(declaredTypeID, declaredTypeHandle) : this.GetDataContract(declaredTypeHandle, declaredType);
verifyKnownType = this.WriteTypeInfo(xmlWriter, dataContract, declaredContract);
this.HandleCollectionAssignedToObject(declaredType, ref dataContract, ref obj, ref verifyKnownType);
}
if (isInterface)
{
VerifyObjectCompatibilityWithInterface(dataContract, obj, declaredType);
}
base.SerializeAndVerifyType(dataContract, xmlWriter, obj, verifyKnownType, declaredType.TypeHandle, declaredType);
}
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:XmlObjectSerializerWriteContextComplexJson.cs
示例3: WriteObjectHandleExceptions
internal void WriteObjectHandleExceptions(XmlWriterDelegator writer, object graph, DataContractResolver dataContractResolver)
{
try
{
CheckNull(writer, "writer");
if (DiagnosticUtility.ShouldTraceInformation)
{
TraceUtility.Trace(TraceEventType.Information, TraceCode.WriteObjectBegin,
SR.GetString(SR.TraceCodeWriteObjectBegin), new StringTraceRecord("Type", GetTypeInfo(GetSerializeType(graph))));
InternalWriteObject(writer, graph, dataContractResolver);
TraceUtility.Trace(TraceEventType.Information, TraceCode.WriteObjectEnd,
SR.GetString(SR.TraceCodeWriteObjectEnd), new StringTraceRecord("Type", GetTypeInfo(GetSerializeType(graph))));
}
else
{
InternalWriteObject(writer, graph, dataContractResolver);
}
}
catch (XmlException ex)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex));
}
catch (FormatException ex)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex));
}
}
示例4: ReflectionWriteClass
public void ReflectionWriteClass(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract, XmlDictionaryString[] memberNames)
{
InvokeOnSerializing(obj, context, classContract);
obj = ResolveAdapterType(obj, classContract);
ReflectionWriteMembers(xmlWriter, obj, context, classContract, classContract, 0 /*childElementIndex*/, memberNames);
InvokeOnSerialized(obj, context, classContract);
}
示例5: WriteJsonValueCore
public override void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
{
DataContractSerializer serializer = new DataContractSerializer(Type.GetTypeFromHandle(declaredTypeHandle), this.GetKnownTypesFromContext(context, (context == null) ? null : context.SerializerKnownTypeList), 1, false, false, null);
MemoryStream stream = new MemoryStream();
serializer.WriteObject(stream, obj);
stream.Position = 0L;
string str = new StreamReader(stream).ReadToEnd();
jsonWriter.WriteString(str);
}
示例6: WriteString
internal override void WriteString(XmlWriterDelegator xmlWriter, string value, XmlDictionaryString name, XmlDictionaryString ns)
#endif
{
if (value == null)
WriteNull(xmlWriter, typeof(string), true/*isMemberTypeSerializable*/, name, ns);
else
{
xmlWriter.WriteStartElementPrimitive(name, ns);
if (!OnHandleReference(xmlWriter, value, false /*canContainCyclicReference*/))
xmlWriter.WriteString(value);
xmlWriter.WriteEndElementPrimitive();
}
}
示例7: WriteRootElement
internal override void WriteRootElement(XmlWriterDelegator writer, XmlDictionaryString name, XmlDictionaryString ns)
{
if (object.ReferenceEquals(ns, DictionaryGlobals.SerializationNamespace))
{
writer.WriteStartElement("z", name, ns);
}
else if (((ns != null) && (ns.Value != null)) && (ns.Value.Length > 0))
{
writer.WriteStartElement("q", name, ns);
}
else
{
writer.WriteStartElement(name, ns);
}
}
示例8: ReflectionInitArgs
private void ReflectionInitArgs(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract classContract)
{
if (obj.GetType() == typeof(DateTimeOffset))
{
obj = DateTimeOffsetAdapter.GetDateTimeOffsetAdapter((DateTimeOffset)obj);
}
else if (obj.GetType().GetTypeInfo().IsGenericType && obj.GetType().GetGenericTypeDefinition() == typeof(KeyValuePair<,>))
{
obj = classContract.KeyValuePairAdapterConstructorInfo.Invoke(new object[] { obj });
}
_arg0XmlWriter = xmlWriter;
_arg1Object = obj;
_arg2Context = context;
_arg3ClassDataContract = classContract;
}
示例9: WriteCollectionToXml
public void WriteCollectionToXml (XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, CollectionDataContract collectionContract)
{
this.writer = xmlWriter;
this.obj = obj;
this.ctx = context;
this.dataContract = collectionContract;
InitArgs (collectionContract.UnderlyingType);
// DemandMemberAccessPermission(memberAccessFlag);
if (collectionContract.IsReadOnlyContract)
{
DataContract.ThrowInvalidDataContractException (collectionContract.SerializationExceptionMessage, null);
}
WriteCollection (collectionContract);
}
示例10: WriteObjectHandleExceptions
internal void WriteObjectHandleExceptions(XmlWriterDelegator writer, object graph, DataContractResolver dataContractResolver)
{
try
{
CheckNull(writer, nameof(writer));
{
InternalWriteObject(writer, graph, dataContractResolver);
}
}
catch (XmlException ex)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex));
}
catch (FormatException ex)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(GetTypeInfoError(SR.ErrorSerializing, GetSerializeType(graph), ex), ex));
}
}
示例11: WriteToXml
public void WriteToXml (XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, ClassDataContract dataContract)
{
this.writer = xmlWriter;
this.obj = obj;
this.ctx = context;
this.dataContract = dataContract;
InitArgs (classContract.UnderlyingType);
// DemandSerializationFormatterPermission (classContract) - irrelevant
// DemandMemberAccessPermission (memberAccessFlag) - irrelevant
if (classContract.IsReadOnlyContract)
{
DataContract.ThrowInvalidDataContractException (classContract.SerializationExceptionMessage, null);
}
WriteClass (classContract);
}
示例12: WriteXmlValue
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context)
{
writer.WriteChar((char) obj);
}
示例13: WriteJsonValue
public void WriteJsonValue(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
{
PushKnownDataContracts(context);
WriteJsonValueCore(jsonWriter, obj, context, declaredTypeHandle);
PopKnownDataContracts(context);
}
示例14: WriteJsonValueCore
public virtual void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle)
{
TraditionalDataContract.WriteXmlValue(jsonWriter, obj, context);
}
示例15: TryWritePrimitive
private bool TryWritePrimitive(Type type, object value, XmlWriterDelegator writer, XmlObjectSerializerWriteContext context)
{
PrimitiveDataContract primitiveContract = PrimitiveDataContract.GetPrimitiveDataContract(type);
if (primitiveContract == null || primitiveContract.UnderlyingType == Globals.TypeOfObject)
return false;
writer.WriteAttributeString(Globals.XsiPrefix, "type", null, "x:" + primitiveContract.StableName.Name);
primitiveContract.WriteXmlValue(writer, value, context);
return true;
}