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); }
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)); } }
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); }
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; }
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); }
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(); } }
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); } }
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; }
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); }
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)); } }
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); }
public void WriteObject(Stream stream, object graph) { _jsonSerializer = new JavaScriptSerializer(stream); DataContract contract = RootContract; Type declaredType = contract.UnderlyingType; Type graphType = (graph == null) ? declaredType : graph.GetType(); System.Runtime.Serialization.XmlWriterDelegator writer = null; if (graph == null) { _jsonSerializer.SerializeObject(null); } else { if (declaredType == graphType) { if (contract.CanContainReferences) { XmlObjectSerializerWriteContextComplexJson context = XmlObjectSerializerWriteContextComplexJson.CreateContext(this, contract); context.SerializeWithoutXsiType(contract, writer, graph, declaredType.TypeHandle); } else { WriteObjectInternal(graph, contract, null, false, declaredType.TypeHandle); } } else { XmlObjectSerializerWriteContextComplexJson context = XmlObjectSerializerWriteContextComplexJson.CreateContext(this, RootContract); contract = DataContractSerializer.GetDataContract(contract, declaredType, graphType); if (contract.CanContainReferences) { context.SerializeWithXsiTypeAtTopLevel(contract, writer, graph, declaredType.TypeHandle, graphType); } else { context.SerializeWithoutXsiType(contract, writer, graph, declaredType.TypeHandle); } } } }
internal void InternalWriteObjectContent(XmlWriterDelegator writer, object graph, DataContractResolver dataContractResolver) { if (MaxItemsInObjectGraph == 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph))); DataContract contract = RootContract; Type declaredType = contract.UnderlyingType; Type graphType = (graph == null) ? declaredType : graph.GetType(); if (_serializationSurrogateProvider != null) { graph = SurrogateToDataContractType(_serializationSurrogateProvider, graph, declaredType, ref graphType); } if (dataContractResolver == null) dataContractResolver = this.DataContractResolver; if (graph == null) { if (IsRootXmlAny(_rootName, contract)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsAnyCannotBeNull, declaredType))); WriteNull(writer); } else { if (declaredType == graphType) { if (contract.CanContainReferences) { XmlObjectSerializerWriteContext context = XmlObjectSerializerWriteContext.CreateContext(this, contract , dataContractResolver ); context.HandleGraphAtTopLevel(writer, graph, contract); context.SerializeWithoutXsiType(contract, writer, graph, declaredType.TypeHandle); } else { contract.WriteXmlValue(writer, graph, null); } } else { XmlObjectSerializerWriteContext context = null; if (IsRootXmlAny(_rootName, contract)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.Format(SR.IsAnyCannotBeSerializedAsDerivedType, graphType, contract.UnderlyingType))); contract = GetDataContract(contract, declaredType, graphType); context = XmlObjectSerializerWriteContext.CreateContext(this, RootContract , dataContractResolver ); if (contract.CanContainReferences) { context.HandleGraphAtTopLevel(writer, graph, contract); } context.OnHandleIsReference(writer, contract, graph); context.SerializeWithXsiTypeAtTopLevel(contract, writer, graph, declaredType.TypeHandle, graphType); } } }
public override void WriteString(XmlWriterDelegator xmlWriter, string value, XmlDictionaryString name, XmlDictionaryString ns)
public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context) { xmlWriter.WriteAnyType(obj); }
internal override void InternalWriteStartObject(XmlWriterDelegator writer, object?graph) { WriteRootElement(writer, RootContract, _rootName, _rootNamespace, _needsContractNsAtRoot); }
internal override bool WriteClrTypeInfo(XmlWriterDelegator xmlWriter, Type dataContractType, string clrTypeName, string clrAssemblyName) { return(false); }
public override void WriteString(XmlWriterDelegator xmlWriter, string value)
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteBase64((byte[])obj); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { throw new NotImplementedException(); }
public override void WriteXmlElement(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString ns) { throw new NotImplementedException(); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteBoolean((bool)obj); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteSignedByte((sbyte)obj); }
public override void WriteXmlElement(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString ns) { context.WriteQName(writer, (XmlQualifiedName)obj, name, ns); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteQName((XmlQualifiedName)obj); }
public override void WriteXmlElement(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString ns) { writer.WriteUri((Uri)obj, name, ns); }
private void WriteExceptionValue(XmlWriterDelegator writer, object value, XmlObjectSerializerWriteContext context) { /* * Every private field present in System.Exception that is serialized in the thick framework is also serialized in this method. * For classes that inherit from System.Exception all public properties are serialized. * The reason that the Members property is not used here to get the properties to serialize is because Members contains only the properties with setters. */ Type type = value.GetType(); writer.WriteXmlnsAttribute("x", new XmlDictionary(1).Add(Globals.SchemaNamespace)); WriteSystemExceptionRequiredValues(writer, value, context); PropertyInfo[] props = type.GetProperties(); foreach (PropertyInfo prop in props) { //Properties in System.Exception are handled in the call to WriteSystemExceptionRequiredValues, we don't want to repeat these properties. if (PropertyIsSystemExceptionProperty(prop)) continue; writer.WriteStartElement(prop.Name, ""); DataContract propDataContract = context.GetDataContract(prop.PropertyType); if (prop.GetValue(value) != null && propDataContract != null && !TryCheckIfNoCountIDictionary(prop.PropertyType, prop.GetValue(value))) { if (!TryWritePrimitive(prop.PropertyType, prop.GetValue(value), writer, context)) { writer.WriteAttributeString(Globals.XsiPrefix, "type", null, "a:" + propDataContract.StableName.Name); writer.WriteXmlnsAttribute("a", new XmlDictionary(1).Add(propDataContract.StableName.Namespace)); context.SerializeWithoutXsiType(propDataContract, writer, prop.GetValue(value), prop.PropertyType.TypeHandle); } } else { writer.WriteAttributeString(Globals.XsiPrefix, "nil", null, "true"); } writer.WriteEndElement(); } }
void InternalWriteObjectContent(XmlWriterDelegator writer, object graph, DataContract contract, Hashtable surrogateDataContracts) { if (MaxItemsInObjectGraph == 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.ExceededMaxItemsQuota, MaxItemsInObjectGraph))); if (IsRootXmlAny(rootName, contract)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.IsAnyNotSupportedByNetDataContractSerializer, contract.UnderlyingType))); } else if (graph == null) { WriteNull(writer); } else { Type graphType = graph.GetType(); if (contract.UnderlyingType != graphType) contract = GetDataContract(graph, ref surrogateDataContracts); XmlObjectSerializerWriteContext context = null; if (contract.CanContainReferences) { context = XmlObjectSerializerWriteContext.CreateContext(this, surrogateDataContracts); context.HandleGraphAtTopLevel(writer, graph, contract); } WriteClrTypeInfo(writer, contract, binder); contract.WriteXmlValue(writer, graph, context); } }
public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context) { Type type = obj.GetType(); if (!(typeof(Exception).IsAssignableFrom(type))) { throw new InvalidDataContractException("Cannot use ExceptionDataContract to serialize object with type: " + type); } WriteExceptionValue(xmlWriter, obj, context); }
// Update the overloads whenever you are changing this method internal static void WriteClrTypeInfo(XmlWriterDelegator writer, Type dataContractType, SerializationBinder binder, string defaultClrTypeName, string defaultClrAssemblyName) { string clrTypeName = null; string clrAssemblyName = null; if (binder != null) { binder.BindToName(dataContractType, out clrAssemblyName, out clrTypeName); } if (clrTypeName == null) { clrTypeName = defaultClrTypeName; } if (clrAssemblyName == null) { clrAssemblyName = defaultClrAssemblyName; } WriteClrTypeInfo(writer, clrTypeName, clrAssemblyName); }
public override void WriteXmlElement(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString ns) { xmlWriter.WriteStartElement(name, ns); xmlWriter.WriteBase64((byte[])obj); xmlWriter.WriteEndElement(); }
static void WriteClrTypeInfo(XmlWriterDelegator writer, string clrTypeName, string clrAssemblyName) { if (clrTypeName != null) writer.WriteAttributeString(Globals.SerPrefix, DictionaryGlobals.ClrTypeLocalName, DictionaryGlobals.SerializationNamespace, DataContract.GetClrTypeString(clrTypeName)); if (clrAssemblyName != null) writer.WriteAttributeString(Globals.SerPrefix, DictionaryGlobals.ClrAssemblyLocalName, DictionaryGlobals.SerializationNamespace, DataContract.GetClrTypeString(clrAssemblyName)); }
internal override void InternalWriteObjectContent(XmlWriterDelegator writer, object?graph) { InternalWriteObjectContent(writer, graph, null); }
public virtual void WriteJsonValueCore(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle) { TraditionalDataContract.WriteXmlValue(jsonWriter, obj, context); }
internal override void InternalWriteObject(XmlWriterDelegator writer, object?graph, DataContractResolver?dataContractResolver) { InternalWriteStartObject(writer, graph); InternalWriteObjectContent(writer, graph, dataContractResolver); InternalWriteEndObject(writer); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteChar((char) obj); }
internal override bool WriteClrTypeInfo(XmlWriterDelegator xmlWriter, DataContract dataContract) { return(false); }
internal override void InternalWriteStartObject(XmlWriterDelegator writer, object graph) { WriteRootElement(writer, RootContract, _rootName, _rootNamespace, _needsContractNsAtRoot); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteUnsignedLong((ulong)obj); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { // write nothing }
// Update the overloads whenever you are changing this method internal static void WriteClrTypeInfo(XmlWriterDelegator writer, DataContract dataContract, SerializationBinder binder) { if (!dataContract.IsISerializable && !(dataContract is SurrogateDataContract)) { TypeInformation typeInformation = null; Type clrType = dataContract.OriginalUnderlyingType; string clrTypeName = null; string clrAssemblyName = null; if (binder != null) { binder.BindToName(clrType, out clrAssemblyName, out clrTypeName); } if (clrTypeName == null) { typeInformation = NetDataContractSerializer.GetTypeInformation(clrType); clrTypeName = typeInformation.FullTypeName; } if (clrAssemblyName == null) { clrAssemblyName = (typeInformation == null) ? NetDataContractSerializer.GetTypeInformation(clrType).AssemblyString : typeInformation.AssemblyString; // Throw in the [TypeForwardedFrom] case to prevent a partially trusted assembly from forwarding itself to an assembly with higher privileges if (!UnsafeTypeForwardingEnabled && !clrType.Assembly.IsFullyTrusted && !IsAssemblyNameForwardingSafe(clrType.Assembly.FullName, clrAssemblyName)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(XmlObjectSerializer.CreateSerializationException(SR.GetString(SR.TypeCannotBeForwardedFrom, DataContract.GetClrTypeFullName(clrType), clrType.Assembly.FullName, clrAssemblyName))); } } WriteClrTypeInfo(writer, clrTypeName, clrAssemblyName); } }
public override void WriteXmlElement(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString ns) { xmlWriter.WriteUnsignedLong((ulong)obj, name, ns); }
// Update the overloads whenever you are changing this method internal static void WriteClrTypeInfo(XmlWriterDelegator writer, Type dataContractType, SerializationBinder binder, SerializationInfo serInfo) { TypeInformation typeInformation = null; string clrTypeName = null; string clrAssemblyName = null; if (binder != null) { binder.BindToName(dataContractType, out clrAssemblyName, out clrTypeName); } if (clrTypeName == null) { if (serInfo.IsFullTypeNameSetExplicit) { clrTypeName = serInfo.FullTypeName; } else { typeInformation = NetDataContractSerializer.GetTypeInformation(serInfo.ObjectType); clrTypeName = typeInformation.FullTypeName; } } if (clrAssemblyName == null) { if (serInfo.IsAssemblyNameSetExplicit) { clrAssemblyName = serInfo.AssemblyName; } else { clrAssemblyName = (typeInformation == null) ? NetDataContractSerializer.GetTypeInformation(serInfo.ObjectType).AssemblyString : typeInformation.AssemblyString; } } WriteClrTypeInfo(writer, clrTypeName, clrAssemblyName); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteFloat((float)obj); }
internal override void InternalWriteEndObject(XmlWriterDelegator writer) { writer.WriteEndElement(); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteDecimal((decimal)obj); }
public void WriteJsonValue(XmlWriterDelegator jsonWriter, object obj, XmlObjectSerializerWriteContextComplexJson context, RuntimeTypeHandle declaredTypeHandle) { PushKnownDataContracts(context); WriteJsonValueCore(jsonWriter, obj, context, declaredTypeHandle); PopKnownDataContracts(context); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteDateTime((DateTime)obj); }
internal override void InternalWriteObject(XmlWriterDelegator writer, object graph, DataContractResolver dataContractResolver) { InternalWriteStartObject(writer, graph); InternalWriteObjectContent(writer, graph, dataContractResolver); InternalWriteEndObject(writer); }
public override void WriteXmlElement(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString ns) { xmlWriter.WriteDateTime((DateTime)obj, name, ns); }
internal override void InternalWriteObjectContent(XmlWriterDelegator writer, object graph) { InternalWriteObjectContent(writer, graph, null); }
public override void WriteXmlValue(XmlWriterDelegator writer, object obj, XmlObjectSerializerWriteContext context) { writer.WriteString((string)obj); }
internal override void InternalWriteEndObject(XmlWriterDelegator writer) { if (!IsRootXmlAny(_rootName, RootContract)) { writer.WriteEndElement(); } }
public override void WriteXmlElement(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context, XmlDictionaryString name, XmlDictionaryString ns) { context.WriteString(xmlWriter, (string)obj, name, ns); }
private void WriteSystemExceptionRequiredValues(XmlWriterDelegator writer, object value, XmlObjectSerializerWriteContext context) { Dictionary<string, object> exceptionFields = GetExceptionFieldValues((Exception)value); object val; foreach (string key in exceptionFields.Keys) { if (!exceptionFields.TryGetValue(key, out val)) continue; Type fieldType; FieldInfo FieldFind = Globals.TypeOfException.GetField(key, BindingFlags.Instance | BindingFlags.NonPublic); if (FieldFind == null) { val = null; // need to nullify because the private fields that are necessary in Exception have changed. fieldType = typeof(int); // can be any type, it doesn't matter. field type will be used to recover a contract, but the type won't be utilized. } else fieldType = FieldFind.FieldType; string fieldDisplayName; if (EssentialExceptionFields.TryGetValue(key, out fieldDisplayName)) writer.WriteStartElement(fieldDisplayName, ""); else writer.WriteStartElement(key, ""); DataContract fieldDataContract = context.GetDataContract(fieldType); if (val != null && fieldDataContract != null && !TryCheckIfNoCountIDictionary(fieldType, val)) { if (!TryWritePrimitive(fieldType, val, writer, context)) { writer.WriteAttributeString(Globals.XsiPrefix, "type", null, "a:" + fieldDataContract.StableName.Name); writer.WriteXmlnsAttribute("a", new XmlDictionary(1).Add(fieldDataContract.StableName.Namespace)); fieldDataContract.WriteXmlValue(writer, val, context); } } else { writer.WriteAttributeString(Globals.XsiPrefix, "nil", null, "true"); } writer.WriteEndElement(); } }
public override void WriteQName(XmlWriterDelegator xmlWriter, XmlQualifiedName value, XmlDictionaryString name, XmlDictionaryString ns)
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; }
public override void WriteAnyType(XmlWriterDelegator xmlWriter, object value)
public override void WriteXmlValue(XmlWriterDelegator xmlWriter, object obj, XmlObjectSerializerWriteContext context) { if (context == null) XmlObjectSerializerWriteContext.WriteRootIXmlSerializable(xmlWriter, obj); else context.WriteIXmlSerializable(xmlWriter, obj); }
public override void WriteQName(XmlWriterDelegator xmlWriter, XmlQualifiedName value)