Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Runtime / Serialization / Formatters / Binary / BinaryFormatter.cs / 1305376 / BinaryFormatter.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: BinaryFormatter ** ** ** Purpose: Soap XML Formatter ** ** ===========================================================*/ namespace System.Runtime.Serialization.Formatters.Binary { using System; using System.IO; using System.Reflection; using System.Globalization; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization.Formatters; #if FEATURE_REMOTING using System.Runtime.Remoting.Proxies; #endif using System.Runtime.Remoting; using System.Runtime.Remoting.Messaging; using System.Runtime.Serialization; using System.Security.Permissions; using System.Diagnostics.Contracts; [System.Runtime.InteropServices.ComVisible(true)] sealed public class BinaryFormatter : #if !FEATURE_REMOTING IFormatter #endif #if NOT_DEFINED , // CoreCLR: to make parser work we have to have comma after the interface name #endif #if FEATURE_REMOTING IRemotingFormatter #endif { internal ISurrogateSelector m_surrogates; internal StreamingContext m_context; internal SerializationBinder m_binder; //internal FormatterTypeStyle m_typeFormat = FormatterTypeStyle.TypesWhenNeeded; internal FormatterTypeStyle m_typeFormat = FormatterTypeStyle.TypesAlways; // For version resiliency, always put out types internal FormatterAssemblyStyle m_assemblyFormat = FormatterAssemblyStyle.Simple; internal TypeFilterLevel m_securityLevel = TypeFilterLevel.Full; internal Object[] m_crossAppDomainArray = null; private static DictionarytypeNameCache = new Dictionary (); // Property which specifies how types are serialized, // FormatterTypeStyle Enum specifies options public FormatterTypeStyle TypeFormat { get { return m_typeFormat; } set { m_typeFormat = value; } } // Property which specifies how types are serialized, // FormatterAssemblyStyle Enum specifies options public FormatterAssemblyStyle AssemblyFormat { get { return m_assemblyFormat; } set { m_assemblyFormat = value; } } // Property which specifies the security level of formatter // TypeFilterLevel Enum specifies options public TypeFilterLevel FilterLevel { get { return m_securityLevel; } set { m_securityLevel = value; } } public ISurrogateSelector SurrogateSelector { get { return m_surrogates; } set { m_surrogates = value; } } public SerializationBinder Binder { get { return m_binder; } set { m_binder = value; } } public StreamingContext Context { get { return m_context; } set { m_context = value; } } // Constructor public BinaryFormatter() { m_surrogates = null; m_context = new StreamingContext(StreamingContextStates.All); } // Constructor public BinaryFormatter(ISurrogateSelector selector, StreamingContext context) { m_surrogates = selector; m_context = context; } // Deserialize the stream into an object graph. [System.Security.SecuritySafeCritical] // auto-generated public Object Deserialize(Stream serializationStream) { return Deserialize(serializationStream, null); } [System.Security.SecurityCritical] // auto-generated internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck) { #if FEATURE_REMOTING return Deserialize(serializationStream, handler, fCheck, null); #else if (serializationStream == null) { throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", serializationStream)); } Contract.EndContractBlock(); if (serializationStream.CanSeek && (serializationStream.Length == 0)) throw new SerializationException(Environment.GetResourceString("Serialization_Stream")); SerTrace.Log(this, "Deserialize Entry"); InternalFE formatterEnums = new InternalFE(); formatterEnums.FEtypeFormat = m_typeFormat; formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary; formatterEnums.FEassemblyFormat = m_assemblyFormat; formatterEnums.FEsecurityLevel = m_securityLevel; ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder); sor.crossAppDomainArray = m_crossAppDomainArray; return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck); #endif } // Deserialize the stream into an object graph. [System.Security.SecuritySafeCritical] // auto-generated public Object Deserialize(Stream serializationStream, HeaderHandler handler) { return Deserialize(serializationStream, handler, true); } #if FEATURE_REMOTING [System.Security.SecuritySafeCritical] // auto-generated public Object DeserializeMethodResponse(Stream serializationStream, HeaderHandler handler, IMethodCallMessage methodCallMessage) { return Deserialize(serializationStream, handler, true, methodCallMessage); } #endif [System.Security.SecurityCritical] // auto-generated_required [System.Runtime.InteropServices.ComVisible(false)] public Object UnsafeDeserialize(Stream serializationStream, HeaderHandler handler) { return Deserialize(serializationStream, handler, false); } #if FEATURE_REMOTING [System.Security.SecurityCritical] // auto-generated_required [System.Runtime.InteropServices.ComVisible(false)] public Object UnsafeDeserializeMethodResponse(Stream serializationStream, HeaderHandler handler, IMethodCallMessage methodCallMessage) { return Deserialize(serializationStream, handler, false, methodCallMessage); } [System.Security.SecurityCritical] // auto-generated internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, IMethodCallMessage methodCallMessage) { return Deserialize(serializationStream, handler, fCheck, false/*isCrossAppDomain*/, methodCallMessage); } // Deserialize the stream into an object graph. [System.Security.SecurityCritical] // auto-generated internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage) { if (serializationStream==null) { throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName",serializationStream)); } Contract.EndContractBlock(); if (serializationStream.CanSeek && (serializationStream.Length == 0)) throw new SerializationException(Environment.GetResourceString("Serialization_Stream")); SerTrace.Log(this, "Deserialize Entry"); InternalFE formatterEnums = new InternalFE(); formatterEnums.FEtypeFormat = m_typeFormat; formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary; formatterEnums.FEassemblyFormat = m_assemblyFormat; formatterEnums.FEsecurityLevel = m_securityLevel; ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder); sor.crossAppDomainArray = m_crossAppDomainArray; return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck, isCrossAppDomain, methodCallMessage); } #endif // FEATURE_REMOTING [System.Security.SecuritySafeCritical] // auto-generated public void Serialize(Stream serializationStream, Object graph) { Serialize(serializationStream, graph, null); } // Commences the process of serializing the entire graph. All of the data (in the appropriate format // is emitted onto the stream). [System.Security.SecuritySafeCritical] // auto-generated public void Serialize(Stream serializationStream, Object graph, Header[] headers) { Serialize(serializationStream, graph, headers, true); } // Commences the process of serializing the entire graph. All of the data (in the appropriate format // is emitted onto the stream). [System.Security.SecurityCritical] // auto-generated internal void Serialize(Stream serializationStream, Object graph, Header[] headers, bool fCheck) { if (serializationStream == null) { throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", serializationStream)); } Contract.EndContractBlock(); SerTrace.Log(this, "Serialize Entry"); InternalFE formatterEnums = new InternalFE(); formatterEnums.FEtypeFormat = m_typeFormat; formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary; formatterEnums.FEassemblyFormat = m_assemblyFormat; ObjectWriter sow = new ObjectWriter(m_surrogates, m_context, formatterEnums, m_binder); __BinaryWriter binaryWriter = new __BinaryWriter(serializationStream, sow, m_typeFormat); sow.Serialize(graph, headers, binaryWriter, fCheck); m_crossAppDomainArray = sow.crossAppDomainArray; } internal static TypeInformation GetTypeInformation(Type type) { lock (typeNameCache) { TypeInformation typeInformation = null; if (!typeNameCache.TryGetValue(type, out typeInformation)) { typeInformation = new TypeInformation(FormatterServices.GetClrTypeFullName(type), FormatterServices.GetClrAssemblyName(type)); typeNameCache.Add(type, typeInformation); } return typeInformation; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: BinaryFormatter ** ** ** Purpose: Soap XML Formatter ** ** ===========================================================*/ namespace System.Runtime.Serialization.Formatters.Binary { using System; using System.IO; using System.Reflection; using System.Globalization; using System.Collections; using System.Collections.Generic; using System.Runtime.Serialization.Formatters; #if FEATURE_REMOTING using System.Runtime.Remoting.Proxies; #endif using System.Runtime.Remoting; using System.Runtime.Remoting.Messaging; using System.Runtime.Serialization; using System.Security.Permissions; using System.Diagnostics.Contracts; [System.Runtime.InteropServices.ComVisible(true)] sealed public class BinaryFormatter : #if !FEATURE_REMOTING IFormatter #endif #if NOT_DEFINED , // CoreCLR: to make parser work we have to have comma after the interface name #endif #if FEATURE_REMOTING IRemotingFormatter #endif { internal ISurrogateSelector m_surrogates; internal StreamingContext m_context; internal SerializationBinder m_binder; //internal FormatterTypeStyle m_typeFormat = FormatterTypeStyle.TypesWhenNeeded; internal FormatterTypeStyle m_typeFormat = FormatterTypeStyle.TypesAlways; // For version resiliency, always put out types internal FormatterAssemblyStyle m_assemblyFormat = FormatterAssemblyStyle.Simple; internal TypeFilterLevel m_securityLevel = TypeFilterLevel.Full; internal Object[] m_crossAppDomainArray = null; private static Dictionary typeNameCache = new Dictionary (); // Property which specifies how types are serialized, // FormatterTypeStyle Enum specifies options public FormatterTypeStyle TypeFormat { get { return m_typeFormat; } set { m_typeFormat = value; } } // Property which specifies how types are serialized, // FormatterAssemblyStyle Enum specifies options public FormatterAssemblyStyle AssemblyFormat { get { return m_assemblyFormat; } set { m_assemblyFormat = value; } } // Property which specifies the security level of formatter // TypeFilterLevel Enum specifies options public TypeFilterLevel FilterLevel { get { return m_securityLevel; } set { m_securityLevel = value; } } public ISurrogateSelector SurrogateSelector { get { return m_surrogates; } set { m_surrogates = value; } } public SerializationBinder Binder { get { return m_binder; } set { m_binder = value; } } public StreamingContext Context { get { return m_context; } set { m_context = value; } } // Constructor public BinaryFormatter() { m_surrogates = null; m_context = new StreamingContext(StreamingContextStates.All); } // Constructor public BinaryFormatter(ISurrogateSelector selector, StreamingContext context) { m_surrogates = selector; m_context = context; } // Deserialize the stream into an object graph. [System.Security.SecuritySafeCritical] // auto-generated public Object Deserialize(Stream serializationStream) { return Deserialize(serializationStream, null); } [System.Security.SecurityCritical] // auto-generated internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck) { #if FEATURE_REMOTING return Deserialize(serializationStream, handler, fCheck, null); #else if (serializationStream == null) { throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", serializationStream)); } Contract.EndContractBlock(); if (serializationStream.CanSeek && (serializationStream.Length == 0)) throw new SerializationException(Environment.GetResourceString("Serialization_Stream")); SerTrace.Log(this, "Deserialize Entry"); InternalFE formatterEnums = new InternalFE(); formatterEnums.FEtypeFormat = m_typeFormat; formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary; formatterEnums.FEassemblyFormat = m_assemblyFormat; formatterEnums.FEsecurityLevel = m_securityLevel; ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder); sor.crossAppDomainArray = m_crossAppDomainArray; return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck); #endif } // Deserialize the stream into an object graph. [System.Security.SecuritySafeCritical] // auto-generated public Object Deserialize(Stream serializationStream, HeaderHandler handler) { return Deserialize(serializationStream, handler, true); } #if FEATURE_REMOTING [System.Security.SecuritySafeCritical] // auto-generated public Object DeserializeMethodResponse(Stream serializationStream, HeaderHandler handler, IMethodCallMessage methodCallMessage) { return Deserialize(serializationStream, handler, true, methodCallMessage); } #endif [System.Security.SecurityCritical] // auto-generated_required [System.Runtime.InteropServices.ComVisible(false)] public Object UnsafeDeserialize(Stream serializationStream, HeaderHandler handler) { return Deserialize(serializationStream, handler, false); } #if FEATURE_REMOTING [System.Security.SecurityCritical] // auto-generated_required [System.Runtime.InteropServices.ComVisible(false)] public Object UnsafeDeserializeMethodResponse(Stream serializationStream, HeaderHandler handler, IMethodCallMessage methodCallMessage) { return Deserialize(serializationStream, handler, false, methodCallMessage); } [System.Security.SecurityCritical] // auto-generated internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, IMethodCallMessage methodCallMessage) { return Deserialize(serializationStream, handler, fCheck, false/*isCrossAppDomain*/, methodCallMessage); } // Deserialize the stream into an object graph. [System.Security.SecurityCritical] // auto-generated internal Object Deserialize(Stream serializationStream, HeaderHandler handler, bool fCheck, bool isCrossAppDomain, IMethodCallMessage methodCallMessage) { if (serializationStream==null) { throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName",serializationStream)); } Contract.EndContractBlock(); if (serializationStream.CanSeek && (serializationStream.Length == 0)) throw new SerializationException(Environment.GetResourceString("Serialization_Stream")); SerTrace.Log(this, "Deserialize Entry"); InternalFE formatterEnums = new InternalFE(); formatterEnums.FEtypeFormat = m_typeFormat; formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary; formatterEnums.FEassemblyFormat = m_assemblyFormat; formatterEnums.FEsecurityLevel = m_securityLevel; ObjectReader sor = new ObjectReader(serializationStream, m_surrogates, m_context, formatterEnums, m_binder); sor.crossAppDomainArray = m_crossAppDomainArray; return sor.Deserialize(handler, new __BinaryParser(serializationStream, sor), fCheck, isCrossAppDomain, methodCallMessage); } #endif // FEATURE_REMOTING [System.Security.SecuritySafeCritical] // auto-generated public void Serialize(Stream serializationStream, Object graph) { Serialize(serializationStream, graph, null); } // Commences the process of serializing the entire graph. All of the data (in the appropriate format // is emitted onto the stream). [System.Security.SecuritySafeCritical] // auto-generated public void Serialize(Stream serializationStream, Object graph, Header[] headers) { Serialize(serializationStream, graph, headers, true); } // Commences the process of serializing the entire graph. All of the data (in the appropriate format // is emitted onto the stream). [System.Security.SecurityCritical] // auto-generated internal void Serialize(Stream serializationStream, Object graph, Header[] headers, bool fCheck) { if (serializationStream == null) { throw new ArgumentNullException("serializationStream", Environment.GetResourceString("ArgumentNull_WithParamName", serializationStream)); } Contract.EndContractBlock(); SerTrace.Log(this, "Serialize Entry"); InternalFE formatterEnums = new InternalFE(); formatterEnums.FEtypeFormat = m_typeFormat; formatterEnums.FEserializerTypeEnum = InternalSerializerTypeE.Binary; formatterEnums.FEassemblyFormat = m_assemblyFormat; ObjectWriter sow = new ObjectWriter(m_surrogates, m_context, formatterEnums, m_binder); __BinaryWriter binaryWriter = new __BinaryWriter(serializationStream, sow, m_typeFormat); sow.Serialize(graph, headers, binaryWriter, fCheck); m_crossAppDomainArray = sow.crossAppDomainArray; } internal static TypeInformation GetTypeInformation(Type type) { lock (typeNameCache) { TypeInformation typeInformation = null; if (!typeNameCache.TryGetValue(type, out typeInformation)) { typeInformation = new TypeInformation(FormatterServices.GetClrTypeFullName(type), FormatterServices.GetClrAssemblyName(type)); typeNameCache.Add(type, typeInformation); } return typeInformation; } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DiagnosticTraceRecords.cs
- InvalidContentTypeException.cs
- FormViewPagerRow.cs
- MenuAdapter.cs
- TreeNodeSelectionProcessor.cs
- DataErrorValidationRule.cs
- TabItem.cs
- DesignerVerb.cs
- UnmanagedBitmapWrapper.cs
- IProvider.cs
- ParallelEnumerableWrapper.cs
- PeerCollaborationPermission.cs
- SettingsPropertyIsReadOnlyException.cs
- QueryPageSettingsEventArgs.cs
- DetailsViewRow.cs
- DataControlFieldCell.cs
- followingsibling.cs
- DrawingAttributes.cs
- DataGridPagingPage.cs
- AuthenticatedStream.cs
- ColorConvertedBitmap.cs
- IisTraceWebEventProvider.cs
- SQLBinary.cs
- SamlAuthorizationDecisionClaimResource.cs
- Visual.cs
- ActivityStatusChangeEventArgs.cs
- AssemblyGen.cs
- CodeNamespaceImport.cs
- FontUnit.cs
- ObjectViewEntityCollectionData.cs
- ManipulationStartedEventArgs.cs
- CannotUnloadAppDomainException.cs
- ListBox.cs
- MD5.cs
- TreeWalker.cs
- FormatterConverter.cs
- ByteViewer.cs
- BuildProviderAppliesToAttribute.cs
- basevalidator.cs
- DirectoryRootQuery.cs
- Quad.cs
- SettingsAttributes.cs
- BooleanFunctions.cs
- PageTheme.cs
- Pkcs9Attribute.cs
- HMACSHA1.cs
- BaseParser.cs
- Schema.cs
- IgnoreDeviceFilterElement.cs
- XmlAttributes.cs
- AsyncCompletedEventArgs.cs
- ButtonBaseAdapter.cs
- CachedPathData.cs
- ConditionalAttribute.cs
- Span.cs
- StylusPointCollection.cs
- GreenMethods.cs
- UndoEngine.cs
- MdiWindowListItemConverter.cs
- HtmlTable.cs
- SettingsContext.cs
- xmlsaver.cs
- ChineseLunisolarCalendar.cs
- SecureUICommand.cs
- HijriCalendar.cs
- RuleSettingsCollection.cs
- ExternalCalls.cs
- DebugTracing.cs
- ExpressionBuilder.cs
- SoapReflectionImporter.cs
- TextElementEnumerator.cs
- RawMouseInputReport.cs
- ResizingMessageFilter.cs
- BorderGapMaskConverter.cs
- OdbcTransaction.cs
- __Filters.cs
- XmlParserContext.cs
- DefaultValueAttribute.cs
- InputManager.cs
- SiteMapDataSourceDesigner.cs
- HuffModule.cs
- Region.cs
- FilterQuery.cs
- Hex.cs
- CommandTreeTypeHelper.cs
- WindowsListBox.cs
- TableLayoutPanelDesigner.cs
- SetStoryboardSpeedRatio.cs
- ConstructorBuilder.cs
- DesignerValidatorAdapter.cs
- ColorAnimationUsingKeyFrames.cs
- WebPartDisplayMode.cs
- SqlDataSourceStatusEventArgs.cs
- ClientTargetCollection.cs
- ClosureBinding.cs
- DetailsViewPageEventArgs.cs
- InfoCardServiceInstallComponent.cs
- ReverseInheritProperty.cs
- AutomationPeer.cs
- ObjectSecurityT.cs