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
- CommandLineParser.cs
- HtmlControlPersistable.cs
- DateTimeFormatInfo.cs
- NavigationCommands.cs
- DbExpressionBuilder.cs
- GregorianCalendarHelper.cs
- Size3DConverter.cs
- BitStream.cs
- EtwTrace.cs
- ReliableSessionBindingElementImporter.cs
- OLEDB_Enum.cs
- ContainerParagraph.cs
- Thumb.cs
- SettingsProviderCollection.cs
- XmlNodeReader.cs
- VerbConverter.cs
- SpeakInfo.cs
- DriveInfo.cs
- AddressingProperty.cs
- FixedPageProcessor.cs
- LineUtil.cs
- PrintDocument.cs
- Win32Native.cs
- ExponentialEase.cs
- ListItem.cs
- MultiplexingFormatMapping.cs
- CaseInsensitiveComparer.cs
- DataRowCollection.cs
- DataIdProcessor.cs
- DefaultHttpHandler.cs
- PerfService.cs
- ListViewInsertionMark.cs
- BoolExpression.cs
- LinkUtilities.cs
- BamlBinaryReader.cs
- IPGlobalProperties.cs
- DelegatingTypeDescriptionProvider.cs
- RealProxy.cs
- GlyphsSerializer.cs
- MultiView.cs
- DragStartedEventArgs.cs
- XmlSignatureProperties.cs
- DBSqlParser.cs
- ISO2022Encoding.cs
- COM2IDispatchConverter.cs
- Wildcard.cs
- ControllableStoryboardAction.cs
- OdbcRowUpdatingEvent.cs
- ServiceEndpointCollection.cs
- ProgramNode.cs
- SqlUdtInfo.cs
- Identity.cs
- TextSelectionProcessor.cs
- SoapInteropTypes.cs
- ConfigurationValidatorBase.cs
- WinFormsUtils.cs
- FixedBufferAttribute.cs
- DefaultMemberAttribute.cs
- SurrogateDataContract.cs
- JsonSerializer.cs
- DbSetClause.cs
- ColorAnimation.cs
- ExtensionFile.cs
- TTSVoice.cs
- EdmProviderManifest.cs
- CapabilitiesRule.cs
- SqlBuilder.cs
- FilteredXmlReader.cs
- TemplatedWizardStep.cs
- PeerDuplexChannel.cs
- PropertyBuilder.cs
- ExpressionWriter.cs
- RowBinding.cs
- WindowsRichEdit.cs
- DbCommandTree.cs
- ClientUIRequest.cs
- AuthenticationManager.cs
- EncodingDataItem.cs
- FixedSOMContainer.cs
- SequenceDesignerAccessibleObject.cs
- PriorityRange.cs
- XmlCharCheckingReader.cs
- SymLanguageType.cs
- StopStoryboard.cs
- HtmlInputReset.cs
- DLinqTableProvider.cs
- SoapFormatExtensions.cs
- BindingContext.cs
- TextRunCacheImp.cs
- ComponentEvent.cs
- XPathParser.cs
- WindowsRichEdit.cs
- DllHostedComPlusServiceHost.cs
- NetworkCredential.cs
- DataView.cs
- MonikerUtility.cs
- CodeConditionStatement.cs
- AutomationProperty.cs
- ICspAsymmetricAlgorithm.cs
- ClientTargetCollection.cs