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
- ComponentChangedEvent.cs
- ObservableDictionary.cs
- WindowsSlider.cs
- EntitySqlQueryState.cs
- CodeComment.cs
- ToolStripLabel.cs
- Axis.cs
- UIElement.cs
- XmlNamespaceManager.cs
- ByeOperationAsyncResult.cs
- _UriSyntax.cs
- ReplyChannel.cs
- CodeDirectiveCollection.cs
- RSAPKCS1KeyExchangeFormatter.cs
- MessageEventSubscriptionService.cs
- MailBnfHelper.cs
- StatusBarItemAutomationPeer.cs
- SmiXetterAccessMap.cs
- SQLInt64Storage.cs
- ColumnResult.cs
- DataGridViewCellStyleChangedEventArgs.cs
- HttpListenerRequest.cs
- Soap.cs
- Tag.cs
- VirtualDirectoryMappingCollection.cs
- PeerApplicationLaunchInfo.cs
- DynamicRenderer.cs
- ReadOnlyDictionary.cs
- TextTreeInsertUndoUnit.cs
- MouseButton.cs
- Int64KeyFrameCollection.cs
- ToolStripActionList.cs
- BookmarkTable.cs
- Parser.cs
- HttpProfileBase.cs
- ListViewEditEventArgs.cs
- CodePrimitiveExpression.cs
- Border.cs
- AppDomain.cs
- SqlResolver.cs
- FocusChangedEventArgs.cs
- UmAlQuraCalendar.cs
- PasswordTextNavigator.cs
- StylusButtonEventArgs.cs
- EventProviderWriter.cs
- WebPartVerbsEventArgs.cs
- KnownTypesProvider.cs
- StrokeCollection2.cs
- KeyFrames.cs
- DragDeltaEventArgs.cs
- MexNamedPipeBindingCollectionElement.cs
- Point.cs
- ObjectDisposedException.cs
- StorageSetMapping.cs
- MimeTypePropertyAttribute.cs
- BitmapPalettes.cs
- CompositionTarget.cs
- TypeUtils.cs
- ServiceCredentials.cs
- Point.cs
- DataColumn.cs
- TypeSemantics.cs
- InfoCardTrace.cs
- DetailsViewDeletedEventArgs.cs
- httpapplicationstate.cs
- StreamGeometry.cs
- AstTree.cs
- ToolStripDropDown.cs
- PrefixQName.cs
- ExpressionNode.cs
- SolidColorBrush.cs
- SqlNodeAnnotation.cs
- PasswordDeriveBytes.cs
- XmlSchemaSimpleTypeRestriction.cs
- MatrixUtil.cs
- ITreeGenerator.cs
- Renderer.cs
- _ListenerRequestStream.cs
- NewExpression.cs
- CrossSiteScriptingValidation.cs
- StreamGeometryContext.cs
- RelOps.cs
- FieldBuilder.cs
- ManagementScope.cs
- ColumnMapTranslator.cs
- SecurityTokenSerializer.cs
- XmlSerializationGeneratedCode.cs
- CompilerErrorCollection.cs
- RadialGradientBrush.cs
- PointCollectionValueSerializer.cs
- ProcessHostFactoryHelper.cs
- RemotingException.cs
- WindowProviderWrapper.cs
- CustomErrorsSection.cs
- Schema.cs
- PropertyTabAttribute.cs
- MailDefinition.cs
- ModelItemCollection.cs
- CacheVirtualItemsEvent.cs
- SynchronizationContext.cs