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
- SamlAuthorityBinding.cs
- XPathSingletonIterator.cs
- BrowserCapabilitiesCodeGenerator.cs
- ErrorWrapper.cs
- ResourceExpression.cs
- NamedElement.cs
- PropertyGeneratedEventArgs.cs
- ToolBarButton.cs
- UnauthorizedWebPart.cs
- OutputCacheSection.cs
- XmlSchemaFacet.cs
- DataTemplateSelector.cs
- HttpResponse.cs
- SchemaTableColumn.cs
- ClientUtils.cs
- DateRangeEvent.cs
- DependencyPropertyKind.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- XsdValidatingReader.cs
- x509store.cs
- ValidationResult.cs
- EventLogPermission.cs
- Point3DAnimationUsingKeyFrames.cs
- WebPartDisplayModeCancelEventArgs.cs
- SystemIPInterfaceProperties.cs
- Rijndael.cs
- ObjectStateEntryDbUpdatableDataRecord.cs
- PasswordBoxAutomationPeer.cs
- PreProcessInputEventArgs.cs
- WinEventTracker.cs
- SwitchAttribute.cs
- PeerMessageDispatcher.cs
- BooleanSwitch.cs
- XamlReaderHelper.cs
- Route.cs
- TrackingProfileSerializer.cs
- RuntimeCompatibilityAttribute.cs
- SqlGenericUtil.cs
- ProgressBar.cs
- RepeaterItem.cs
- MdbDataFileEditor.cs
- FaultPropagationQuery.cs
- DataGridViewCellFormattingEventArgs.cs
- PerspectiveCamera.cs
- ColorInterpolationModeValidation.cs
- AdornerHitTestResult.cs
- CaseInsensitiveComparer.cs
- ClientType.cs
- GridViewCellAutomationPeer.cs
- OneOfScalarConst.cs
- DataViewSettingCollection.cs
- TrayIconDesigner.cs
- CapabilitiesUse.cs
- WorkerRequest.cs
- HttpListenerResponse.cs
- TextTreePropertyUndoUnit.cs
- OrthographicCamera.cs
- ClassHandlersStore.cs
- ErrorStyle.cs
- Repeater.cs
- ToRequest.cs
- RenamedEventArgs.cs
- FrameworkContentElement.cs
- QueryOptionExpression.cs
- NullExtension.cs
- webclient.cs
- CheckBoxPopupAdapter.cs
- MouseButtonEventArgs.cs
- StandardOleMarshalObject.cs
- BooleanToSelectiveScrollingOrientationConverter.cs
- MobileListItemCollection.cs
- SiteMapProvider.cs
- ListChangedEventArgs.cs
- ScriptResourceInfo.cs
- ApplicationServiceManager.cs
- Package.cs
- Triplet.cs
- XamlClipboardData.cs
- StreamGeometry.cs
- RightsManagementLicense.cs
- Block.cs
- base64Transforms.cs
- HelpInfo.cs
- Rotation3DAnimation.cs
- CounterSample.cs
- Win32MouseDevice.cs
- KerberosSecurityTokenParameters.cs
- Ipv6Element.cs
- WindowsToolbarAsMenu.cs
- XmlMtomReader.cs
- SyndicationDeserializer.cs
- ActionItem.cs
- followingsibling.cs
- DataGridViewCellFormattingEventArgs.cs
- SapiGrammar.cs
- controlskin.cs
- HtmlInputHidden.cs
- LocatorGroup.cs
- VerificationAttribute.cs
- SqlLiftIndependentRowExpressions.cs