Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Serializer / SimpleTypesSurrogate.cs / 1305376 / SimpleTypesSurrogate.cs
namespace System.Workflow.ComponentModel.Serialization { using System; using System.Xml; using System.Runtime.Serialization; using System.Reflection; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Collections; using System.Collections.Generic; #region SimpleTypesSurrogate //This class is currently used only for Guids. The size diff is 93 bytes per guid over binary formatter //Will add support for other types as well, eventually. internal sealed class SimpleTypesSurrogate : ISerializationSurrogate { enum TypeID : byte { Guid = 1, Null, } void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context) { if (obj.GetType() == typeof(Guid)) { Guid guid = (Guid)obj; info.AddValue("typeID", TypeID.Guid); info.AddValue("bits", guid.ToByteArray()); } } object ISerializationSurrogate.SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { TypeID typeID = (TypeID)info.GetValue("typeID", typeof(TypeID)); if (typeID == TypeID.Guid) return new Guid(info.GetValue("bits", typeof(byte[])) as byte[]); return null; } } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Workflow.ComponentModel.Serialization { using System; using System.Xml; using System.Runtime.Serialization; using System.Reflection; using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Collections; using System.Collections.Generic; #region SimpleTypesSurrogate //This class is currently used only for Guids. The size diff is 93 bytes per guid over binary formatter //Will add support for other types as well, eventually. internal sealed class SimpleTypesSurrogate : ISerializationSurrogate { enum TypeID : byte { Guid = 1, Null, } void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context) { if (obj.GetType() == typeof(Guid)) { Guid guid = (Guid)obj; info.AddValue("typeID", TypeID.Guid); info.AddValue("bits", guid.ToByteArray()); } } object ISerializationSurrogate.SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { TypeID typeID = (TypeID)info.GetValue("typeID", typeof(TypeID)); if (typeID == TypeID.Guid) return new Guid(info.GetValue("bits", typeof(byte[])) as byte[]); return null; } } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- counter.cs
- TextLineResult.cs
- SEHException.cs
- _SSPISessionCache.cs
- TypeInfo.cs
- DependencyPropertyChangedEventArgs.cs
- OutputWindow.cs
- Directory.cs
- WebUtil.cs
- Size.cs
- HttpResponseHeader.cs
- Message.cs
- DefaultPropertyAttribute.cs
- OleDbPropertySetGuid.cs
- ZipIOModeEnforcingStream.cs
- WebPartMenuStyle.cs
- WebScriptServiceHost.cs
- BitmapFrame.cs
- SchemaMerger.cs
- DataGridBoundColumn.cs
- HostingEnvironmentException.cs
- Cursors.cs
- WorkflowViewService.cs
- DockProviderWrapper.cs
- ServiceContractViewControl.cs
- TreeNodeMouseHoverEvent.cs
- GeometryDrawing.cs
- BeginStoryboard.cs
- WpfKnownType.cs
- RoleGroupCollection.cs
- Simplifier.cs
- HttpConfigurationSystem.cs
- AssemblyCacheEntry.cs
- Queue.cs
- EntityProxyFactory.cs
- IntSecurity.cs
- hwndwrapper.cs
- DrawingImage.cs
- FrameworkObject.cs
- StaticResourceExtension.cs
- TypeSystemHelpers.cs
- SQLDecimalStorage.cs
- InternalResources.cs
- unsafeIndexingFilterStream.cs
- Typeface.cs
- PersonalizableAttribute.cs
- Rotation3D.cs
- SqlNamer.cs
- PerformanceCountersElement.cs
- ServiceModelReg.cs
- MenuAdapter.cs
- AsyncContentLoadedEventArgs.cs
- SvcMapFileSerializer.cs
- WebPartTransformerAttribute.cs
- Menu.cs
- RemoteWebConfigurationHostStream.cs
- SiteMapNode.cs
- InfoCardRSAPKCS1KeyExchangeDeformatter.cs
- RenderOptions.cs
- SerialReceived.cs
- ChtmlPageAdapter.cs
- ButtonBaseDesigner.cs
- SplashScreen.cs
- PeerDuplexChannelListener.cs
- COM2IDispatchConverter.cs
- NegationPusher.cs
- HMACRIPEMD160.cs
- DesignerActionList.cs
- InternalPermissions.cs
- SelectingProviderEventArgs.cs
- IdentifierCollection.cs
- XmlEncodedRawTextWriter.cs
- FilteredDataSetHelper.cs
- DataRow.cs
- ScriptManager.cs
- SchemaNotation.cs
- UDPClient.cs
- XAMLParseException.cs
- RootProfilePropertySettingsCollection.cs
- NewArray.cs
- ModelChangedEventArgsImpl.cs
- CodeTypeConstructor.cs
- ToolStripItemDesigner.cs
- DependencyPropertyValueSerializer.cs
- _NestedSingleAsyncResult.cs
- NamespaceInfo.cs
- ListBindingHelper.cs
- ConstructorBuilder.cs
- SqlDataReader.cs
- DataListGeneralPage.cs
- DrawItemEvent.cs
- ClientEventManager.cs
- TCEAdapterGenerator.cs
- AsyncStreamReader.cs
- ReturnType.cs
- AudioStateChangedEventArgs.cs
- TabPage.cs
- MobileFormsAuthentication.cs
- Char.cs
- MsmqIntegrationAppDomainProtocolHandler.cs