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
- LifetimeServices.cs
- ApplicationProxyInternal.cs
- CultureSpecificStringDictionary.cs
- RecognizerStateChangedEventArgs.cs
- ListInitExpression.cs
- FrameDimension.cs
- DictionaryGlobals.cs
- ToolStripItemImageRenderEventArgs.cs
- SecurityUniqueId.cs
- ConfigurationException.cs
- MTConfigUtil.cs
- CDSCollectionETWBCLProvider.cs
- MeasureItemEvent.cs
- filewebrequest.cs
- ListBox.cs
- FunctionQuery.cs
- GraphicsContainer.cs
- WorkflowApplicationEventArgs.cs
- ForeignKeyConstraint.cs
- XamlWriterExtensions.cs
- ServiceCredentialsElement.cs
- ResXBuildProvider.cs
- Oid.cs
- TraceHandlerErrorFormatter.cs
- DependencyPropertyKey.cs
- TextTreeRootNode.cs
- ModelItemCollectionImpl.cs
- DetailsViewRowCollection.cs
- Vector3DIndependentAnimationStorage.cs
- RuntimeHandles.cs
- HttpConfigurationSystem.cs
- MapPathBasedVirtualPathProvider.cs
- TextReader.cs
- BindingWorker.cs
- VerticalAlignConverter.cs
- XmlILAnnotation.cs
- DataListItemCollection.cs
- StringBuilder.cs
- TriggerCollection.cs
- ArraySegment.cs
- _HeaderInfoTable.cs
- GroupAggregateExpr.cs
- SqlDependency.cs
- TypeBuilderInstantiation.cs
- WebPartDescription.cs
- SingleAnimationBase.cs
- GenericEnumConverter.cs
- ScaleTransform3D.cs
- RotateTransform.cs
- DataGridViewColumnStateChangedEventArgs.cs
- TripleDES.cs
- XamlSerializerUtil.cs
- GeneralTransform3DCollection.cs
- SafeNativeMethodsCLR.cs
- HttpConfigurationSystem.cs
- HttpModulesSection.cs
- InheritablePropertyChangeInfo.cs
- RegexRunnerFactory.cs
- PhoneCall.cs
- TaskSchedulerException.cs
- XmlSchemaExternal.cs
- IndependentlyAnimatedPropertyMetadata.cs
- SQLDecimalStorage.cs
- BindingGraph.cs
- ImpersonationContext.cs
- PersonalizationProviderCollection.cs
- indexingfiltermarshaler.cs
- BaseValidator.cs
- SectionInput.cs
- MachineKeyConverter.cs
- HandlerWithFactory.cs
- DataGridColumnHeaderCollection.cs
- BufferManager.cs
- SmiMetaData.cs
- BaseDataBoundControl.cs
- RectangleHotSpot.cs
- IPipelineRuntime.cs
- DetailsViewInsertedEventArgs.cs
- StatusBarPanel.cs
- ChildChangedEventArgs.cs
- TextAdaptor.cs
- SchemaElementDecl.cs
- PerfService.cs
- ScriptingRoleServiceSection.cs
- TabItem.cs
- UriScheme.cs
- XmlEncoding.cs
- MenuStrip.cs
- VectorAnimation.cs
- Screen.cs
- MaterialGroup.cs
- TlsSspiNegotiation.cs
- HtmlPhoneCallAdapter.cs
- XmlSchemaObject.cs
- EndpointNotFoundException.cs
- ContainerSelectorBehavior.cs
- Utility.cs
- AnnotationAuthorChangedEventArgs.cs
- HttpGetProtocolReflector.cs
- LoadGrammarCompletedEventArgs.cs