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
- _NegoState.cs
- MatrixAnimationUsingPath.cs
- ModuleBuilderData.cs
- HyperLink.cs
- EmptyCollection.cs
- SqlConnectionHelper.cs
- SqlDeflator.cs
- IdentityModelDictionary.cs
- OleDbWrapper.cs
- Int16Storage.cs
- CharStorage.cs
- HostedHttpRequestAsyncResult.cs
- Point3DCollection.cs
- RunInstallerAttribute.cs
- SerializerProvider.cs
- IriParsingElement.cs
- EdmProperty.cs
- DrawingBrush.cs
- SetIterators.cs
- RelationshipDetailsRow.cs
- SvcMapFileSerializer.cs
- FixUp.cs
- SynchronizationContextHelper.cs
- RtfControls.cs
- SafeNativeMethods.cs
- GlyphCache.cs
- ChineseLunisolarCalendar.cs
- RegisteredArrayDeclaration.cs
- StickyNoteHelper.cs
- TableLayoutColumnStyleCollection.cs
- _HeaderInfo.cs
- HtmlDocument.cs
- ResumeStoryboard.cs
- SafeUserTokenHandle.cs
- ResourceReferenceExpression.cs
- Hashtable.cs
- SelectingProviderEventArgs.cs
- RuntimeHelpers.cs
- ReferencedAssembly.cs
- ReflectionUtil.cs
- _NegoStream.cs
- BreakRecordTable.cs
- TimeSpanHelper.cs
- ChannelManagerService.cs
- ListBoxItemAutomationPeer.cs
- TimeEnumHelper.cs
- ObjectQueryState.cs
- SchemaTableColumn.cs
- SafeSerializationManager.cs
- TextBoxLine.cs
- precedingsibling.cs
- AnonymousIdentificationSection.cs
- InstanceDataCollection.cs
- DataSourceProvider.cs
- BrowsableAttribute.cs
- ServiceOperationViewControl.cs
- String.cs
- MsmqChannelListenerBase.cs
- XdrBuilder.cs
- WeakReferenceList.cs
- PatternMatcher.cs
- mil_commands.cs
- ItemDragEvent.cs
- NavigationPropertyEmitter.cs
- HtmlInputFile.cs
- BindingWorker.cs
- InkCanvasSelection.cs
- EventLogPermissionAttribute.cs
- NetMsmqBinding.cs
- SelectionItemPatternIdentifiers.cs
- SecurityTokenSerializer.cs
- FileDataSourceCache.cs
- StreamSecurityUpgradeInitiator.cs
- HtmlWindow.cs
- FlowLayoutPanel.cs
- DefaultValidator.cs
- ActiveXHost.cs
- X509AsymmetricSecurityKey.cs
- CustomTokenProvider.cs
- OLEDB_Util.cs
- QueueProcessor.cs
- DescendantQuery.cs
- CharConverter.cs
- TabItem.cs
- DelegatingTypeDescriptionProvider.cs
- SimpleWebHandlerParser.cs
- MemberDomainMap.cs
- PeerInvitationResponse.cs
- FlowNode.cs
- CultureSpecificStringDictionary.cs
- CodeBlockBuilder.cs
- EntityClientCacheEntry.cs
- DetailsViewPageEventArgs.cs
- LocalServiceSecuritySettingsElement.cs
- SmtpMail.cs
- ConstructorNeedsTagAttribute.cs
- Propagator.JoinPropagator.JoinPredicateVisitor.cs
- GridItemPatternIdentifiers.cs
- Authorization.cs
- X509SubjectKeyIdentifierClause.cs