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
- Tag.cs
- SignatureToken.cs
- AgileSafeNativeMemoryHandle.cs
- HelpKeywordAttribute.cs
- ListViewGroupItemCollection.cs
- ProxyElement.cs
- RelationshipManager.cs
- WindowsSpinner.cs
- SqlParameterizer.cs
- DoubleAnimationUsingKeyFrames.cs
- HttpRuntimeSection.cs
- InputManager.cs
- ListViewItem.cs
- TextEffectCollection.cs
- HttpRequestBase.cs
- NavigateEvent.cs
- RuntimeConfigLKG.cs
- XmlValidatingReaderImpl.cs
- TypedLocationWrapper.cs
- AdRotator.cs
- ColumnMapTranslator.cs
- DbException.cs
- DefinitionUpdate.cs
- DateTimeFormatInfo.cs
- CodeArgumentReferenceExpression.cs
- SQLDouble.cs
- ProcessRequestArgs.cs
- HttpRawResponse.cs
- SqlRecordBuffer.cs
- XmlProcessingInstruction.cs
- ReachSerializationUtils.cs
- GeneralTransform3D.cs
- SiteOfOriginContainer.cs
- MenuItemStyle.cs
- QuaternionAnimationUsingKeyFrames.cs
- DeflateStream.cs
- DataGridAddNewRow.cs
- EventLogPermissionAttribute.cs
- MailDefinitionBodyFileNameEditor.cs
- KeyFrames.cs
- ReflectionTypeLoadException.cs
- MarkupCompilePass1.cs
- DocumentViewer.cs
- MSAAWinEventWrap.cs
- ContextStack.cs
- AggregateNode.cs
- XmlAttributeOverrides.cs
- CancellableEnumerable.cs
- GifBitmapEncoder.cs
- LassoSelectionBehavior.cs
- CompModSwitches.cs
- ProxyFragment.cs
- NamedPermissionSet.cs
- XmlArrayAttribute.cs
- RedistVersionInfo.cs
- DataGridViewCellMouseEventArgs.cs
- HtmlDocument.cs
- TypeValidationEventArgs.cs
- SystemThemeKey.cs
- RuntimeWrappedException.cs
- MetabaseServerConfig.cs
- DoubleCollectionValueSerializer.cs
- CqlIdentifiers.cs
- ServiceDescriptionSerializer.cs
- WebPartCatalogAddVerb.cs
- TypeListConverter.cs
- EntityContainer.cs
- Win32Native.cs
- UInt32Converter.cs
- BitmapFrame.cs
- AssertFilter.cs
- DocumentAutomationPeer.cs
- InvalidPrinterException.cs
- BinaryVersion.cs
- BitHelper.cs
- EventMap.cs
- EntityClassGenerator.cs
- QueryPageSettingsEventArgs.cs
- Vector3DAnimationBase.cs
- Context.cs
- XmlDocument.cs
- ToolStripLocationCancelEventArgs.cs
- SatelliteContractVersionAttribute.cs
- SqlAliaser.cs
- AttributeQuery.cs
- AccessControlEntry.cs
- FlowLayoutPanel.cs
- WebPartConnectVerb.cs
- GrammarBuilderRuleRef.cs
- RadioButton.cs
- Context.cs
- GenerateTemporaryTargetAssembly.cs
- DataListItemCollection.cs
- InternalsVisibleToAttribute.cs
- ItemsControlAutomationPeer.cs
- StaticTextPointer.cs
- PersonalizationProviderCollection.cs
- FixedSOMPageConstructor.cs
- NativeMethods.cs
- RemoteWebConfigurationHost.cs