public BinaryFormatter(ISurrogateSelector selector, StreamingContext context) { this.m_typeFormat = FormatterTypeStyle.TypesAlways; this.m_securityLevel = TypeFilterLevel.Full; this.m_surrogates = selector; this.m_context = context; }
public BinaryFormatter() { this.m_typeFormat = FormatterTypeStyle.TypesAlways; this.m_securityLevel = TypeFilterLevel.Full; this.m_surrogates = null; this.m_context = new StreamingContext(StreamingContextStates.All); }
internal BinaryFormatterWriter(Stream outputStream, ObjectWriter objectWriter, FormatterTypeStyle formatterTypeStyle) { _outputStream = outputStream; _formatterTypeStyle = formatterTypeStyle; _objectWriter = objectWriter; _dataWriter = new BinaryWriter(outputStream, Encoding.UTF8); }
private static T FormatterClone <T>( T obj, ISerializationSurrogate surrogate = null, FormatterAssemblyStyle assemblyFormat = FormatterAssemblyStyle.Full, TypeFilterLevel filterLevel = TypeFilterLevel.Full, FormatterTypeStyle typeFormat = FormatterTypeStyle.TypesAlways) { BinaryFormatter f; if (surrogate == null) { f = new BinaryFormatter(); } else { var c = new StreamingContext(); var s = new SurrogateSelector(); s.AddSurrogate(obj.GetType(), c, surrogate); f = new BinaryFormatter(s, c); } f.AssemblyFormat = assemblyFormat; f.FilterLevel = filterLevel; f.TypeFormat = typeFormat; using (var s = new MemoryStream()) { f.Serialize(s, obj); Assert.NotEqual(0, s.Position); s.Position = 0; return((T)(f.Deserialize(s))); } }
// Constructor. public BinaryFormatter() { this.context = new StreamingContext(StreamingContextStates.All); this.assemblyFormat = FormatterAssemblyStyle.Full; this.typeFormat = FormatterTypeStyle.TypesAlways; this.filterLevel = TypeFilterLevel.Full; this.converter = new FormatterConverter(); }
public ObjectWriter(ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { this._surrogateSelector = surrogateSelector; this._context = context; this._assemblyFormat = assemblyFormat; this._typeFormat = typeFormat; this._manager = new SerializationObjectManager(context); }
internal __BinaryWriter(Stream sout, ObjectWriter objectWriter, FormatterTypeStyle formatterTypeStyle) { this.sout = sout; this.formatterTypeStyle = formatterTypeStyle; this.objectWriter = objectWriter; this.m_nestedObjectCount = 0; this.dataWriter = new BinaryWriter(sout, Encoding.UTF8); }
// Token: 0x06005262 RID: 21090 RVA: 0x00121364 File Offset: 0x0011F564 internal __BinaryWriter(Stream sout, ObjectWriter objectWriter, FormatterTypeStyle formatterTypeStyle) { this.sout = sout; this.formatterTypeStyle = formatterTypeStyle; this.objectWriter = objectWriter; this.m_nestedObjectCount = 0; this.dataWriter = new BinaryWriter(sout, Encoding.UTF8); }
private int nullCount = 0; //Count of consecutive array nulls // Constructor internal __BinaryWriter(Stream sout, ObjectWriter objectWriter, FormatterTypeStyle formatterTypeStyle) { SerTrace.Log(this, "BinaryWriter "); this.sout = sout; this.formatterTypeStyle = formatterTypeStyle; this.objectWriter = objectWriter; m_nestedObjectCount = 0; dataWriter = new BinaryWriter(sout, Encoding.UTF8); }
public ObjectWriter(BinaryFormatter formatter) { _surrogateSelector = formatter.SurrogateSelector; _context = formatter.Context; _assemblyFormat = formatter.AssemblyFormat; _typeFormat = formatter.TypeFormat; _manager = new SerializationObjectManager(formatter.Context); _binder = formatter.Binder; }
private int nullCount = 0; //Count of consecutive array nulls // Constructor internal __BinaryWriter(Stream sout, ObjectWriter objectWriter, FormatterTypeStyle formatterTypeStyle) { SerTrace.Log( this, "BinaryWriter "); this.sout = sout; this.formatterTypeStyle = formatterTypeStyle; this.objectWriter = objectWriter; m_nestedObjectCount = 0; dataWriter = new BinaryWriter(sout, Encoding.UTF8); }
public BinaryFormatter(ISurrogateSelector selector, StreamingContext context) { this.surrogateSelector = selector; this.context = context; this.assemblyFormat = FormatterAssemblyStyle.Full; this.typeFormat = FormatterTypeStyle.TypesAlways; this.filterLevel = TypeFilterLevel.Full; this.converter = new FormatterConverter(); }
public ObjectWriter(ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { _surrogateSelector = surrogateSelector; _context = context; _assemblyFormat = assemblyFormat; _typeFormat = typeFormat; #if NET_2_0 _manager = new SerializationObjectManager(context); #endif }
internal void Serialize(object objGraph, Header[] headers, FormatterTypeStyle typeFormat, FormatterAssemblyStyle assemblyFormat) { CultureInfo savedCi = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Serialize_inner(objGraph, headers, typeFormat, assemblyFormat); } finally { Thread.CurrentThread.CurrentCulture = savedCi; } _manager.RaiseOnSerializedEvent(); }
// Constructor used by SoapWriter public SoapTypeMapper( XmlTextWriter xmlWriter, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { _xmlWriter = xmlWriter; _assemblyFormat = assemblyFormat; _prefixNumber = 1; //Type elementType = typeof(string); if (typeFormat == FormatterTypeStyle.XsdString) { elementString = new Element("xsd", "string", XmlSchema.Namespace); } else { elementString = new Element(SoapEncodingPrefix, "string", SoapEncodingNamespace); } // typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element); }
public BinaryMessageFormatter (FormatterAssemblyStyle topObjectFormat, FormatterTypeStyle typeFormat) { _formatter = new BinaryFormatter (); _formatter.AssemblyFormat = topObjectFormat; _formatter.TypeFormat = typeFormat; }
private bool CheckTypeFormat(FormatterTypeStyle test, FormatterTypeStyle want) { return(test & want) == want; }
/// <summary> /// Initializes a new instance of the <see cref="BinaryFormatter<T>"/> class. /// </summary> /// <param name="topObjectFormat">The top object format.</param> /// <param name="typeFormat">The type format.</param> public BinaryFormatter(FormatterAssemblyStyle topObjectFormat, FormatterTypeStyle typeFormat) { this.mFormatter.AssemblyFormat = topObjectFormat; this.mFormatter.TypeFormat = typeFormat; }
/// <include file='..\..\doc\BinaryMessageFormatter.uex' path='docs/doc[@for="BinaryMessageFormatter.BinaryMessageFormatter1"]/*' /> /// <devdoc> /// Creates a new Binary message formatter object /// with the given properties. /// </devdoc> public BinaryMessageFormatter(FormatterAssemblyStyle topObjectFormat, FormatterTypeStyle typeFormat) { this.formatter = new BinaryFormatter { AssemblyFormat = topObjectFormat, TypeFormat = typeFormat }; }
public void ValidateBasicObjectsRoundtrip(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat, bool unsafeDeserialize) { object result = FormatterClone(obj, null, assemblyFormat, filterLevel, typeFormat, unsafeDeserialize); if (!ReferenceEquals(obj, string.Empty)) // "" is interned and will roundtrip as the same object { Assert.NotSame(obj, result); } Assert.Equal(obj, result); }
private bool CheckTypeFormat(FormatterTypeStyle test, FormatterTypeStyle want) => (test & want) == want;
public IBinaryConfiguration WithFormat(FormatterTypeStyle format) { _binaryFormatter.TypeFormat = format; return this; }
public void ValidateBasicObjectsRoundtrip(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat) { object clone = BinaryFormatterHelpers.Clone(obj, null, assemblyFormat, filterLevel, typeFormat); // string.Empty and DBNull are both singletons if (!ReferenceEquals(obj, string.Empty) && !(obj is DBNull)) { Assert.NotSame(obj, clone); } EqualityExtensions.CheckEquals(obj, clone, isSamePlatform: true); }
public static void WriteMethodCall(BinaryWriter writer, object obj, Header[] headers, ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { IMethodCallMessage call = (IMethodCallMessage)obj; writer.Write((byte)BinaryElement.MethodCall); MethodFlags methodFlags; int infoArraySize = 0; object info = null; object[] extraProperties = null; if (call.LogicalCallContext != null && call.LogicalCallContext.HasInfo) { methodFlags = MethodFlags.IncludesLogicalCallContext; infoArraySize++; } else { methodFlags = MethodFlags.ExcludeLogicalCallContext; } if (RemotingServices.IsMethodOverloaded(call)) { infoArraySize++; methodFlags |= MethodFlags.IncludesSignature; } if (call.Properties.Count > MethodCallDictionary.InternalKeys.Length) { extraProperties = GetExtraProperties(call.Properties, MethodCallDictionary.InternalKeys); infoArraySize++; } #if NET_2_0 if (call.MethodBase.IsGenericMethod) { infoArraySize++; methodFlags |= MethodFlags.GenericArguments; } #endif if (call.ArgCount == 0) { methodFlags |= MethodFlags.NoArguments; } else { if (AllTypesArePrimitive(call.Args)) { methodFlags |= MethodFlags.PrimitiveArguments; } else { if (infoArraySize == 0) { methodFlags |= MethodFlags.ArgumentsInSimpleArray; } else { methodFlags |= MethodFlags.ArgumentsInMultiArray; infoArraySize++; } } } writer.Write((int)methodFlags); // Method name writer.Write((byte)BinaryTypeCode.String); writer.Write(call.MethodName); // Class name writer.Write((byte)BinaryTypeCode.String); writer.Write(call.TypeName); // Arguments if ((methodFlags & MethodFlags.PrimitiveArguments) > 0) { writer.Write((uint)call.Args.Length); for (int n = 0; n < call.ArgCount; n++) { object arg = call.GetArg(n); if (arg != null) { writer.Write(BinaryCommon.GetTypeCode(arg.GetType())); ObjectWriter.WritePrimitiveValue(writer, arg); } else { writer.Write((byte)BinaryTypeCode.Null); } } } if (infoArraySize > 0) { object[] ainfo = new object[infoArraySize]; int n = 0; if ((methodFlags & MethodFlags.ArgumentsInMultiArray) > 0) { ainfo[n++] = call.Args; } #if NET_2_0 if ((methodFlags & MethodFlags.GenericArguments) > 0) { ainfo[n++] = call.MethodBase.GetGenericArguments(); } #endif if ((methodFlags & MethodFlags.IncludesSignature) > 0) { ainfo[n++] = call.MethodSignature; } if ((methodFlags & MethodFlags.IncludesLogicalCallContext) > 0) { ainfo[n++] = call.LogicalCallContext; } if (extraProperties != null) { ainfo[n++] = extraProperties; } info = ainfo; } else if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > 0) { info = call.Args; } if (info != null) { ObjectWriter objectWriter = new ObjectWriter(surrogateSelector, context, assemblyFormat, typeFormat); objectWriter.WriteObjectGraph(writer, info, headers); } else { writer.Write((byte)BinaryElement.End); } }
public static void WriteMethodCall (BinaryWriter writer, object obj, Header[] headers, ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { IMethodCallMessage call = (IMethodCallMessage)obj; writer.Write ((byte) BinaryElement.MethodCall); MethodFlags methodFlags; int infoArraySize = 0; object info = null; object[] extraProperties = null; if (call.LogicalCallContext != null && call.LogicalCallContext.HasInfo) { methodFlags = MethodFlags.IncludesLogicalCallContext; infoArraySize++; } else methodFlags = MethodFlags.ExcludeLogicalCallContext; if (RemotingServices.IsMethodOverloaded (call)) { infoArraySize++; methodFlags |= MethodFlags.IncludesSignature; } if (call.Properties.Count > MethodCallDictionary.InternalKeys.Length) { extraProperties = GetExtraProperties (call.Properties, MethodCallDictionary.InternalKeys); infoArraySize++; } #if NET_2_0 if (call.MethodBase.IsGenericMethod) { infoArraySize++; methodFlags |= MethodFlags.GenericArguments; } #endif if (call.ArgCount == 0) methodFlags |= MethodFlags.NoArguments; else { if (AllTypesArePrimitive (call.Args)) methodFlags |= MethodFlags.PrimitiveArguments; else { if (infoArraySize == 0) methodFlags |= MethodFlags.ArgumentsInSimpleArray; else { methodFlags |= MethodFlags.ArgumentsInMultiArray; infoArraySize++; } } } writer.Write ((int) methodFlags); // Method name writer.Write ((byte) BinaryTypeCode.String); writer.Write (call.MethodName); // Class name writer.Write ((byte) BinaryTypeCode.String); writer.Write (call.TypeName); // Arguments if ((methodFlags & MethodFlags.PrimitiveArguments) > 0) { writer.Write ((uint)call.Args.Length); for (int n=0; n<call.ArgCount; n++) { object arg = call.GetArg(n); if (arg != null) { writer.Write (BinaryCommon.GetTypeCode (arg.GetType())); ObjectWriter.WritePrimitiveValue (writer, arg); } else writer.Write ((byte)BinaryTypeCode.Null); } } if ( infoArraySize > 0) { object[] ainfo = new object[infoArraySize]; int n=0; if ((methodFlags & MethodFlags.ArgumentsInMultiArray) > 0) ainfo[n++] = call.Args; #if NET_2_0 if ((methodFlags & MethodFlags.GenericArguments) > 0) ainfo[n++] = call.MethodBase.GetGenericArguments (); #endif if ((methodFlags & MethodFlags.IncludesSignature) > 0) ainfo[n++] = call.MethodSignature; if ((methodFlags & MethodFlags.IncludesLogicalCallContext) > 0) ainfo[n++] = call.LogicalCallContext; if (extraProperties != null) ainfo[n++] = extraProperties; info = ainfo; } else if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > 0) info = call.Args; if (info != null) { ObjectWriter objectWriter = new ObjectWriter (surrogateSelector, context, assemblyFormat, typeFormat); objectWriter.WriteObjectGraph (writer, info, headers); } else writer.Write ((byte) BinaryElement.End); }
public static void WriteMethodResponse(BinaryWriter writer, object obj, Header[] headers, ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { IMethodReturnMessage methodReturnMessage = (IMethodReturnMessage)obj; writer.Write(22); string[] array = MethodReturnDictionary.InternalReturnKeys; int num = 0; object obj2 = null; object[] array2 = null; MethodFlags methodFlags = MethodFlags.ExcludeLogicalCallContext; ReturnTypeTag returnTypeTag; if (methodReturnMessage.Exception != null) { returnTypeTag = (ReturnTypeTag)34; array = MethodReturnDictionary.InternalExceptionKeys; num = 1; } else if (methodReturnMessage.ReturnValue == null) { returnTypeTag = ReturnTypeTag.Null; } else if (MessageFormatter.IsMethodPrimitive(methodReturnMessage.ReturnValue.GetType())) { returnTypeTag = ReturnTypeTag.PrimitiveType; } else { returnTypeTag = ReturnTypeTag.ObjectType; num++; } if (methodReturnMessage.LogicalCallContext != null && methodReturnMessage.LogicalCallContext.HasInfo) { methodFlags = MethodFlags.IncludesLogicalCallContext; num++; } if (methodReturnMessage.Properties.Count > array.Length && (byte)(returnTypeTag & ReturnTypeTag.Exception) == 0) { array2 = MessageFormatter.GetExtraProperties(methodReturnMessage.Properties, array); num++; } MethodFlags methodFlags2; if (methodReturnMessage.OutArgCount == 0) { methodFlags2 = MethodFlags.NoArguments; } else if (MessageFormatter.AllTypesArePrimitive(methodReturnMessage.Args)) { methodFlags2 = MethodFlags.PrimitiveArguments; } else if (num == 0) { methodFlags2 = MethodFlags.ArgumentsInSimpleArray; } else { methodFlags2 = MethodFlags.ArgumentsInMultiArray; num++; } writer.Write((byte)(methodFlags | methodFlags2)); writer.Write((byte)returnTypeTag); writer.Write(0); writer.Write(0); if (returnTypeTag == ReturnTypeTag.PrimitiveType) { writer.Write(BinaryCommon.GetTypeCode(methodReturnMessage.ReturnValue.GetType())); ObjectWriter.WritePrimitiveValue(writer, methodReturnMessage.ReturnValue); } if (methodFlags2 == MethodFlags.PrimitiveArguments) { writer.Write((uint)methodReturnMessage.ArgCount); for (int i = 0; i < methodReturnMessage.ArgCount; i++) { object arg = methodReturnMessage.GetArg(i); if (arg != null) { writer.Write(BinaryCommon.GetTypeCode(arg.GetType())); ObjectWriter.WritePrimitiveValue(writer, arg); } else { writer.Write(17); } } } if (num > 0) { object[] array3 = new object[num]; int num2 = 0; if ((byte)(returnTypeTag & ReturnTypeTag.Exception) != 0) { array3[num2++] = methodReturnMessage.Exception; } if (methodFlags2 == MethodFlags.ArgumentsInMultiArray) { array3[num2++] = methodReturnMessage.Args; } if (returnTypeTag == ReturnTypeTag.ObjectType) { array3[num2++] = methodReturnMessage.ReturnValue; } if (methodFlags == MethodFlags.IncludesLogicalCallContext) { array3[num2++] = methodReturnMessage.LogicalCallContext; } if (array2 != null) { array3[num2++] = array2; } obj2 = array3; } else if ((methodFlags2 & MethodFlags.ArgumentsInSimpleArray) > (MethodFlags)0) { obj2 = methodReturnMessage.Args; } if (obj2 != null) { ObjectWriter objectWriter = new ObjectWriter(surrogateSelector, context, assemblyFormat, typeFormat); objectWriter.WriteObjectGraph(writer, obj2, headers); } else { writer.Write(11); } }
public ObjectWriter (BinaryFormatter formatter) { _surrogateSelector = formatter.SurrogateSelector; _context = formatter.Context; _assemblyFormat = formatter.AssemblyFormat; _typeFormat = formatter.TypeFormat; _manager = new SerializationObjectManager (formatter.Context); #if NET_4_0 _binder = formatter.Binder; #endif }
public IBinaryConfiguration WithFormat(FormatterTypeStyle format) { _binaryFormatter.TypeFormat = format; return(this); }
// Constructor used by SoapWriter public SoapTypeMapper( XmlTextWriter xmlWriter, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { _xmlWriter = xmlWriter; _assemblyFormat = assemblyFormat; _prefixNumber = 1; //Type elementType = typeof(string); if(typeFormat == FormatterTypeStyle.XsdString) { elementString = new Element("xsd", "string", XmlSchema.Namespace); } else { elementString = new Element(SoapEncodingPrefix, "string", SoapEncodingNamespace); } // typeToXmlNodeTable.Add(elementType.AssemblyQualifiedName, element); }
private bool CheckTypeFormat(FormatterTypeStyle test, FormatterTypeStyle want) { return((test & want) == want); }
void Serialize_inner(object objGraph, Header[] headers, FormatterTypeStyle typeFormat, FormatterAssemblyStyle assemblyFormat) { _typeFormat = typeFormat; _assemblyFormat = assemblyFormat; // Create the XmlDocument with the // Envelope and Body elements _mapper = new SoapTypeMapper(_xmlWriter, assemblyFormat, typeFormat); // The root element _xmlWriter.WriteStartElement( SoapTypeMapper.SoapEnvelopePrefix, "Envelope", SoapTypeMapper.SoapEnvelopeNamespace); // adding namespaces _xmlWriter.WriteAttributeString( "xmlns", "xsi", "http://www.w3.org/2000/xmlns/", "http://www.w3.org/2001/XMLSchema-instance"); _xmlWriter.WriteAttributeString( "xmlns", "xsd", "http://www.w3.org/2000/xmlns/", XmlSchema.Namespace); _xmlWriter.WriteAttributeString( "xmlns", SoapTypeMapper.SoapEncodingPrefix, "http://www.w3.org/2000/xmlns/", SoapTypeMapper.SoapEncodingNamespace); _xmlWriter.WriteAttributeString( "xmlns", SoapTypeMapper.SoapEnvelopePrefix, "http://www.w3.org/2000/xmlns/", SoapTypeMapper.SoapEnvelopeNamespace); _xmlWriter.WriteAttributeString( "xmlns", "clr", "http://www.w3.org/2000/xmlns/", SoapServices.XmlNsForClrType); _xmlWriter.WriteAttributeString( SoapTypeMapper.SoapEnvelopePrefix, "encodingStyle", SoapTypeMapper.SoapEnvelopeNamespace, "http://schemas.xmlsoap.org/soap/encoding/"); ISoapMessage msg = objGraph as ISoapMessage; if (msg != null) { headers = msg.Headers; } if (headers != null && headers.Length > 0) { _xmlWriter.WriteStartElement(SoapTypeMapper.SoapEnvelopePrefix, "Header", SoapTypeMapper.SoapEnvelopeNamespace); foreach (Header h in headers) { SerializeHeader(h); } WriteObjectQueue(); _xmlWriter.WriteEndElement(); } // The body element _xmlWriter.WriteStartElement( SoapTypeMapper.SoapEnvelopePrefix, "Body", SoapTypeMapper.SoapEnvelopeNamespace); bool firstTime = false; if (msg != null) { SerializeMessage(msg); } else { _objectQueue.Enqueue(new EnqueuedObject(objGraph, idGen.GetId(objGraph, out firstTime))); } WriteObjectQueue(); _xmlWriter.WriteFullEndElement(); // the body element _xmlWriter.WriteFullEndElement(); // the envelope element _xmlWriter.Flush(); }
public static void WriteMethodCall(BinaryWriter writer, object obj, Header[] headers, ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { IMethodCallMessage methodCallMessage = (IMethodCallMessage)obj; writer.Write(21); int num = 0; object obj2 = null; object[] array = null; MethodFlags methodFlags; if (methodCallMessage.LogicalCallContext != null && methodCallMessage.LogicalCallContext.HasInfo) { methodFlags = MethodFlags.IncludesLogicalCallContext; num++; } else { methodFlags = MethodFlags.ExcludeLogicalCallContext; } if (RemotingServices.IsMethodOverloaded(methodCallMessage)) { num++; methodFlags |= MethodFlags.IncludesSignature; } if (methodCallMessage.Properties.Count > MethodCallDictionary.InternalKeys.Length) { array = MessageFormatter.GetExtraProperties(methodCallMessage.Properties, MethodCallDictionary.InternalKeys); num++; } if (methodCallMessage.MethodBase.IsGenericMethod) { num++; methodFlags |= MethodFlags.GenericArguments; } if (methodCallMessage.ArgCount == 0) { methodFlags |= MethodFlags.NoArguments; } else if (MessageFormatter.AllTypesArePrimitive(methodCallMessage.Args)) { methodFlags |= MethodFlags.PrimitiveArguments; } else if (num == 0) { methodFlags |= MethodFlags.ArgumentsInSimpleArray; } else { methodFlags |= MethodFlags.ArgumentsInMultiArray; num++; } writer.Write((int)methodFlags); writer.Write(18); writer.Write(methodCallMessage.MethodName); writer.Write(18); writer.Write(methodCallMessage.TypeName); if ((methodFlags & MethodFlags.PrimitiveArguments) > (MethodFlags)0) { writer.Write((uint)methodCallMessage.Args.Length); for (int i = 0; i < methodCallMessage.ArgCount; i++) { object arg = methodCallMessage.GetArg(i); if (arg != null) { writer.Write(BinaryCommon.GetTypeCode(arg.GetType())); ObjectWriter.WritePrimitiveValue(writer, arg); } else { writer.Write(17); } } } if (num > 0) { object[] array2 = new object[num]; int num2 = 0; if ((methodFlags & MethodFlags.ArgumentsInMultiArray) > (MethodFlags)0) { array2[num2++] = methodCallMessage.Args; } if ((methodFlags & MethodFlags.GenericArguments) > (MethodFlags)0) { array2[num2++] = methodCallMessage.MethodBase.GetGenericArguments(); } if ((methodFlags & MethodFlags.IncludesSignature) > (MethodFlags)0) { array2[num2++] = methodCallMessage.MethodSignature; } if ((methodFlags & MethodFlags.IncludesLogicalCallContext) > (MethodFlags)0) { array2[num2++] = methodCallMessage.LogicalCallContext; } if (array != null) { array2[num2++] = array; } obj2 = array2; } else if ((methodFlags & MethodFlags.ArgumentsInSimpleArray) > (MethodFlags)0) { obj2 = methodCallMessage.Args; } if (obj2 != null) { ObjectWriter objectWriter = new ObjectWriter(surrogateSelector, context, assemblyFormat, typeFormat); objectWriter.WriteObjectGraph(writer, obj2, headers); } else { writer.Write(11); } }
public void ValidateBasicObjectsRoundtrip(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat) { object clone = FormatterClone(obj, null, assemblyFormat, filterLevel, typeFormat); if (!ReferenceEquals(obj, string.Empty)) // "" is interned and will roundtrip as the same object { Assert.NotSame(obj, clone); } CheckForAnyEquals(obj, clone); }
public static void WriteMethodResponse (BinaryWriter writer, object obj, Header[] headers, ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { IMethodReturnMessage resp = (IMethodReturnMessage)obj; writer.Write ((byte) BinaryElement.MethodResponse); string[] internalProperties = MethodReturnDictionary.InternalReturnKeys; int infoArrayLength = 0; object info = null; object[] extraProperties = null; // Type of return value ReturnTypeTag returnTypeTag; MethodFlags contextFlag = MethodFlags.ExcludeLogicalCallContext; if (resp.Exception != null) { returnTypeTag = ReturnTypeTag.Exception | ReturnTypeTag.Null; internalProperties = MethodReturnDictionary.InternalExceptionKeys; infoArrayLength = 1; } else if (resp.ReturnValue == null) { returnTypeTag = ReturnTypeTag.Null; } else if (IsMethodPrimitive(resp.ReturnValue.GetType())) { returnTypeTag = ReturnTypeTag.PrimitiveType; } else { returnTypeTag = ReturnTypeTag.ObjectType; infoArrayLength++; } // Message flags MethodFlags formatFlag; if ((resp.LogicalCallContext != null) && resp.LogicalCallContext.HasInfo) { contextFlag = MethodFlags.IncludesLogicalCallContext; infoArrayLength++; } if (resp.Properties.Count > internalProperties.Length && ((returnTypeTag & ReturnTypeTag.Exception) == 0)) { extraProperties = GetExtraProperties (resp.Properties, internalProperties); infoArrayLength++; } if (resp.OutArgCount == 0) formatFlag = MethodFlags.NoArguments; else { if (AllTypesArePrimitive (resp.Args)) formatFlag = MethodFlags.PrimitiveArguments; else { if (infoArrayLength == 0) formatFlag = MethodFlags.ArgumentsInSimpleArray; else { formatFlag = MethodFlags.ArgumentsInMultiArray; infoArrayLength++; } } } writer.Write ((byte) (contextFlag | formatFlag)); writer.Write ((byte) returnTypeTag); // FIXME: what are the following 2 bytes for? writer.Write ((byte) 0); writer.Write ((byte) 0); // Arguments if (returnTypeTag == ReturnTypeTag.PrimitiveType) { writer.Write (BinaryCommon.GetTypeCode (resp.ReturnValue.GetType())); ObjectWriter.WritePrimitiveValue (writer, resp.ReturnValue); } if (formatFlag == MethodFlags.PrimitiveArguments) { writer.Write ((uint)resp.ArgCount); for (int n=0; n<resp.ArgCount; n++) { object val = resp.GetArg(n); if (val != null) { writer.Write (BinaryCommon.GetTypeCode (val.GetType())); ObjectWriter.WritePrimitiveValue (writer, val); } else writer.Write ((byte)BinaryTypeCode.Null); } } if (infoArrayLength > 0) { object[] infoArray = new object[infoArrayLength]; int n = 0; if ((returnTypeTag & ReturnTypeTag.Exception) != 0) infoArray[n++] = resp.Exception; if (formatFlag == MethodFlags.ArgumentsInMultiArray) infoArray[n++] = resp.Args; if (returnTypeTag == ReturnTypeTag.ObjectType) infoArray[n++] = resp.ReturnValue; if (contextFlag == MethodFlags.IncludesLogicalCallContext) infoArray[n++] = resp.LogicalCallContext; if (extraProperties != null) infoArray[n++] = extraProperties; info = infoArray; } else if ((formatFlag & MethodFlags.ArgumentsInSimpleArray) > 0) info = resp.Args; if (info != null) { ObjectWriter objectWriter = new ObjectWriter (surrogateSelector, context, assemblyFormat, typeFormat); objectWriter.WriteObjectGraph (writer, info, headers); } else writer.Write ((byte) BinaryElement.End); }
public ObjectWriter (ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { _surrogateSelector = surrogateSelector; _context = context; _assemblyFormat = assemblyFormat; _typeFormat = typeFormat; #if NET_2_0 _manager = new SerializationObjectManager (context); #endif }
public static void WriteMethodResponse(BinaryWriter writer, object obj, Header[] headers, ISurrogateSelector surrogateSelector, StreamingContext context, FormatterAssemblyStyle assemblyFormat, FormatterTypeStyle typeFormat) { IMethodReturnMessage resp = (IMethodReturnMessage)obj; writer.Write((byte)BinaryElement.MethodResponse); string[] internalProperties = MethodReturnDictionary.InternalReturnKeys; int infoArrayLength = 0; object info = null; object[] extraProperties = null; // Type of return value ReturnTypeTag returnTypeTag; MethodFlags contextFlag = MethodFlags.ExcludeLogicalCallContext; if (resp.Exception != null) { returnTypeTag = ReturnTypeTag.Exception | ReturnTypeTag.Null; internalProperties = MethodReturnDictionary.InternalExceptionKeys; infoArrayLength = 1; } else if (resp.ReturnValue == null) { returnTypeTag = ReturnTypeTag.Null; } else if (IsMethodPrimitive(resp.ReturnValue.GetType())) { returnTypeTag = ReturnTypeTag.PrimitiveType; } else { returnTypeTag = ReturnTypeTag.ObjectType; infoArrayLength++; } // Message flags MethodFlags formatFlag; if ((resp.LogicalCallContext != null) && resp.LogicalCallContext.HasInfo) { contextFlag = MethodFlags.IncludesLogicalCallContext; infoArrayLength++; } if (resp.Properties.Count > internalProperties.Length && ((returnTypeTag & ReturnTypeTag.Exception) == 0)) { extraProperties = GetExtraProperties(resp.Properties, internalProperties); infoArrayLength++; } if (resp.OutArgCount == 0) { formatFlag = MethodFlags.NoArguments; } else { if (AllTypesArePrimitive(resp.Args)) { formatFlag = MethodFlags.PrimitiveArguments; } else { if (infoArrayLength == 0) { formatFlag = MethodFlags.ArgumentsInSimpleArray; } else { formatFlag = MethodFlags.ArgumentsInMultiArray; infoArrayLength++; } } } writer.Write((byte)(contextFlag | formatFlag)); writer.Write((byte)returnTypeTag); // FIXME: what are the following 2 bytes for? writer.Write((byte)0); writer.Write((byte)0); // Arguments if (returnTypeTag == ReturnTypeTag.PrimitiveType) { writer.Write(BinaryCommon.GetTypeCode(resp.ReturnValue.GetType())); ObjectWriter.WritePrimitiveValue(writer, resp.ReturnValue); } if (formatFlag == MethodFlags.PrimitiveArguments) { writer.Write((uint)resp.ArgCount); for (int n = 0; n < resp.ArgCount; n++) { object val = resp.GetArg(n); if (val != null) { writer.Write(BinaryCommon.GetTypeCode(val.GetType())); ObjectWriter.WritePrimitiveValue(writer, val); } else { writer.Write((byte)BinaryTypeCode.Null); } } } if (infoArrayLength > 0) { object[] infoArray = new object[infoArrayLength]; int n = 0; if ((returnTypeTag & ReturnTypeTag.Exception) != 0) { infoArray[n++] = resp.Exception; } if (formatFlag == MethodFlags.ArgumentsInMultiArray) { infoArray[n++] = resp.Args; } if (returnTypeTag == ReturnTypeTag.ObjectType) { infoArray[n++] = resp.ReturnValue; } if (contextFlag == MethodFlags.IncludesLogicalCallContext) { infoArray[n++] = resp.LogicalCallContext; } if (extraProperties != null) { infoArray[n++] = extraProperties; } info = infoArray; } else if ((formatFlag & MethodFlags.ArgumentsInSimpleArray) > 0) { info = resp.Args; } if (info != null) { ObjectWriter objectWriter = new ObjectWriter(surrogateSelector, context, assemblyFormat, typeFormat); objectWriter.WriteObjectGraph(writer, info, headers); } else { writer.Write((byte)BinaryElement.End); } }
public void ValidateNonSerializableTypes(object obj, FormatterAssemblyStyle assemblyFormat, TypeFilterLevel filterLevel, FormatterTypeStyle typeFormat) { var f = new BinaryFormatter() { AssemblyFormat = assemblyFormat, FilterLevel = filterLevel, TypeFormat = typeFormat }; using (var s = new MemoryStream()) { Assert.Throws <SerializationException>(() => f.Serialize(s, obj)); } }
internal void Serialize (object objGraph, Header[] headers, FormatterTypeStyle typeFormat, FormatterAssemblyStyle assemblyFormat) { CultureInfo savedCi = CultureInfo.CurrentCulture; try { Thread.CurrentThread.CurrentCulture = new CultureInfo("en-US"); Serialize_inner (objGraph, headers, typeFormat, assemblyFormat); } finally { Thread.CurrentThread.CurrentCulture = savedCi; } #if NET_2_0 && !TARGET_JVM _manager.RaiseOnSerializedEvent (); #endif }
public BinaryMessageFormatter(FormatterAssemblyStyle topObjectFormat, FormatterTypeStyle typeFormat) { _formatter = new BinaryFormatter(); _formatter.AssemblyFormat = topObjectFormat; _formatter.TypeFormat = typeFormat; }
void Serialize_inner (object objGraph, Header[] headers, FormatterTypeStyle typeFormat, FormatterAssemblyStyle assemblyFormat) { _typeFormat = typeFormat; _assemblyFormat = assemblyFormat; // Create the XmlDocument with the // Envelope and Body elements _mapper = new SoapTypeMapper(_xmlWriter, assemblyFormat, typeFormat); // The root element _xmlWriter.WriteStartElement( SoapTypeMapper.SoapEnvelopePrefix, "Envelope", SoapTypeMapper.SoapEnvelopeNamespace); // adding namespaces _xmlWriter.WriteAttributeString( "xmlns", "xsi", "http://www.w3.org/2000/xmlns/", "http://www.w3.org/2001/XMLSchema-instance"); _xmlWriter.WriteAttributeString( "xmlns", "xsd", "http://www.w3.org/2000/xmlns/", XmlSchema.Namespace); _xmlWriter.WriteAttributeString( "xmlns", SoapTypeMapper.SoapEncodingPrefix, "http://www.w3.org/2000/xmlns/", SoapTypeMapper.SoapEncodingNamespace); _xmlWriter.WriteAttributeString( "xmlns", SoapTypeMapper.SoapEnvelopePrefix, "http://www.w3.org/2000/xmlns/", SoapTypeMapper.SoapEnvelopeNamespace); _xmlWriter.WriteAttributeString( "xmlns", "clr", "http://www.w3.org/2000/xmlns/", SoapServices.XmlNsForClrType); _xmlWriter.WriteAttributeString( SoapTypeMapper.SoapEnvelopePrefix, "encodingStyle", SoapTypeMapper.SoapEnvelopeNamespace, "http://schemas.xmlsoap.org/soap/encoding/"); ISoapMessage msg = objGraph as ISoapMessage; if (msg != null) headers = msg.Headers; if (headers != null && headers.Length > 0) { _xmlWriter.WriteStartElement (SoapTypeMapper.SoapEnvelopePrefix, "Header", SoapTypeMapper.SoapEnvelopeNamespace); foreach (Header h in headers) SerializeHeader (h); WriteObjectQueue (); _xmlWriter.WriteEndElement (); } // The body element _xmlWriter.WriteStartElement( SoapTypeMapper.SoapEnvelopePrefix, "Body", SoapTypeMapper.SoapEnvelopeNamespace); bool firstTime = false; if (msg != null) SerializeMessage(msg); else _objectQueue.Enqueue(new EnqueuedObject( objGraph, idGen.GetId(objGraph, out firstTime))); WriteObjectQueue (); _xmlWriter.WriteFullEndElement(); // the body element _xmlWriter.WriteFullEndElement(); // the envelope element _xmlWriter.Flush(); }