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
- SqlDependencyUtils.cs
- FunctionNode.cs
- WindowsEditBox.cs
- TextSelectionHighlightLayer.cs
- WebPartEditorOkVerb.cs
- WindowPattern.cs
- BitmapDownload.cs
- WindowsAuthenticationEventArgs.cs
- PlatformCulture.cs
- LOSFormatter.cs
- _OSSOCK.cs
- DataBindingHandlerAttribute.cs
- ParallelForEach.cs
- NavigationCommands.cs
- TraceInternal.cs
- HyperLink.cs
- BuildManagerHost.cs
- ApplicationBuildProvider.cs
- FontDialog.cs
- DataGridViewCellEventArgs.cs
- WebPartEventArgs.cs
- FontUnitConverter.cs
- _SecureChannel.cs
- SerialReceived.cs
- SecurityUtils.cs
- DataGridHeaderBorder.cs
- SqlUserDefinedAggregateAttribute.cs
- smtppermission.cs
- parserscommon.cs
- DataAccessor.cs
- StopStoryboard.cs
- Convert.cs
- FileSystemInfo.cs
- GenerateHelper.cs
- TreeNodeStyleCollection.cs
- SelectionItemProviderWrapper.cs
- ProxyHwnd.cs
- MetadataHelper.cs
- CommonObjectSecurity.cs
- SecurityPolicySection.cs
- IncrementalHitTester.cs
- EUCJPEncoding.cs
- ObjectDisposedException.cs
- RealizationDrawingContextWalker.cs
- SafeRegistryHandle.cs
- CategoryGridEntry.cs
- ExpressionPrinter.cs
- IdentityNotMappedException.cs
- X509Certificate2Collection.cs
- EdmSchemaAttribute.cs
- RowType.cs
- keycontainerpermission.cs
- OpenTypeLayoutCache.cs
- ReferenceEqualityComparer.cs
- DBConnection.cs
- ScaleTransform.cs
- NonVisualControlAttribute.cs
- ProvidersHelper.cs
- StrokeNodeEnumerator.cs
- TextSelection.cs
- Tablet.cs
- MessageSmuggler.cs
- SmiEventSink_DeferedProcessing.cs
- RawStylusInputCustomDataList.cs
- VectorAnimationUsingKeyFrames.cs
- CompositeControl.cs
- HostVisual.cs
- Walker.cs
- SignatureHelper.cs
- ModuleBuilder.cs
- ObsoleteAttribute.cs
- MarshalByValueComponent.cs
- cookieexception.cs
- QilStrConcatenator.cs
- FileLogRecord.cs
- DispatchChannelSink.cs
- Missing.cs
- DeferredTextReference.cs
- BoolExpressionVisitors.cs
- Assert.cs
- BulletChrome.cs
- BrowserDefinition.cs
- TextServicesHost.cs
- AssemblyCache.cs
- MULTI_QI.cs
- HtmlWindowCollection.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- DesignerTextBoxAdapter.cs
- NativeActivityTransactionContext.cs
- GeometryHitTestResult.cs
- CheckBoxStandardAdapter.cs
- DataSvcMapFileSerializer.cs
- InputMethodStateChangeEventArgs.cs
- WebServiceParameterData.cs
- ClientData.cs
- MenuAdapter.cs
- ProcessModelInfo.cs
- ContextMenuStripActionList.cs
- DataControlFieldHeaderCell.cs
- PinProtectionHelper.cs