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
- XmlSchemaSubstitutionGroup.cs
- Repeater.cs
- WebInvokeAttribute.cs
- TextTreeTextBlock.cs
- ServicePointManagerElement.cs
- KeySpline.cs
- CharEnumerator.cs
- RealProxy.cs
- DataTemplateSelector.cs
- HandlerFactoryWrapper.cs
- PanelStyle.cs
- SchemaTypeEmitter.cs
- CharacterString.cs
- AsymmetricSignatureDeformatter.cs
- CodeConstructor.cs
- TimeStampChecker.cs
- HtmlHistory.cs
- figurelength.cs
- UnmanagedBitmapWrapper.cs
- CodeLinePragma.cs
- PlanCompilerUtil.cs
- EditorAttribute.cs
- DuplicateWaitObjectException.cs
- CheckBoxStandardAdapter.cs
- FileUtil.cs
- BitStack.cs
- StorageEndPropertyMapping.cs
- FontCollection.cs
- SpeechSeg.cs
- ListItemCollection.cs
- UnhandledExceptionEventArgs.cs
- WindowsButton.cs
- DesignerDataConnection.cs
- BinaryOperationBinder.cs
- Expression.cs
- ClrPerspective.cs
- DataTableNewRowEvent.cs
- NameValueSectionHandler.cs
- ValidationErrorCollection.cs
- DataGridViewCellFormattingEventArgs.cs
- OdbcParameter.cs
- CompletionProxy.cs
- Group.cs
- Int32RectValueSerializer.cs
- addressfiltermode.cs
- JulianCalendar.cs
- PartialTrustVisibleAssemblyCollection.cs
- AssemblyName.cs
- EntryPointNotFoundException.cs
- ContextQuery.cs
- ContextStaticAttribute.cs
- ILGenerator.cs
- DefaultProxySection.cs
- TransactionProtocol.cs
- DataGridViewTextBoxEditingControl.cs
- MatrixAnimationUsingPath.cs
- ValueTypeFixupInfo.cs
- Stroke.cs
- SizeIndependentAnimationStorage.cs
- XmlSerializerNamespaces.cs
- SafeCancelMibChangeNotify.cs
- AuthenticationSection.cs
- SBCSCodePageEncoding.cs
- SQLCharsStorage.cs
- OrderPreservingMergeHelper.cs
- DataGridSortCommandEventArgs.cs
- StringFunctions.cs
- ISFTagAndGuidCache.cs
- ThemeInfoAttribute.cs
- XmlSchemaRedefine.cs
- ItemsPanelTemplate.cs
- Visitors.cs
- WebEventTraceProvider.cs
- QuaternionKeyFrameCollection.cs
- PartialArray.cs
- dsa.cs
- CaseStatement.cs
- ErrorItem.cs
- GlobalProxySelection.cs
- AppSecurityManager.cs
- RuntimeConfigLKG.cs
- DescendantQuery.cs
- DocobjHost.cs
- DataContractSerializerOperationBehavior.cs
- TemplateKeyConverter.cs
- ExceptionTrace.cs
- Wizard.cs
- TreeNodeBinding.cs
- XhtmlMobileTextWriter.cs
- VisualStyleRenderer.cs
- HttpValueCollection.cs
- HebrewCalendar.cs
- PageCatalogPart.cs
- UIElementIsland.cs
- WebConfigurationManager.cs
- FtpCachePolicyElement.cs
- ComNativeDescriptor.cs
- ExpressionBuilderContext.cs
- ManifestSignedXml.cs
- TypeCacheManager.cs