Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities.DurableInstancing / System / Activities / DurableInstancing / DefaultObjectSerializer.cs / 1305376 / DefaultObjectSerializer.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.DurableInstancing { using System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Runtime.Serialization; using System.Xml; using System.Xml.Linq; using System.Xml.Serialization; class DefaultObjectSerializer : IObjectSerializer { NetDataContractSerializer serializer; public DefaultObjectSerializer() { this.serializer = new NetDataContractSerializer(); } public DictionaryDeserializePropertyBag(byte[] serializedValue) { using (MemoryStream memoryStream = new MemoryStream(serializedValue)) { return this.DeserializePropertyBag(memoryStream); } } public object DeserializeValue(byte[] serializedValue) { using (MemoryStream memoryStream = new MemoryStream(serializedValue)) { return this.DeserializeValue(memoryStream); } } public ArraySegment SerializePropertyBag(Dictionary value) { using (MemoryStream memoryStream = new MemoryStream(4096)) { this.SerializePropertyBag(memoryStream, value); return new ArraySegment (memoryStream.GetBuffer(), 0, Convert.ToInt32(memoryStream.Length)); } } public ArraySegment SerializeValue(object value) { using (MemoryStream memoryStream = new MemoryStream(4096)) { this.SerializeValue(memoryStream, value); return new ArraySegment (memoryStream.GetBuffer(), 0, Convert.ToInt32(memoryStream.Length)); } } protected virtual Dictionary DeserializePropertyBag(Stream stream) { using (XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max)) { Dictionary propertyBag = new Dictionary (); if (dictionaryReader.ReadToDescendant("Property")) { do { dictionaryReader.Read(); KeyValuePair property = (KeyValuePair ) this.serializer.ReadObject(dictionaryReader); propertyBag.Add(property.Key, property.Value); } while (dictionaryReader.ReadToNextSibling("Property")); } return propertyBag; } } protected virtual object DeserializeValue(Stream stream) { using (XmlDictionaryReader dictionaryReader = XmlDictionaryReader.CreateBinaryReader(stream, XmlDictionaryReaderQuotas.Max)) { return this.serializer.ReadObject(dictionaryReader); } } protected virtual void SerializePropertyBag(Stream stream, Dictionary propertyBag) { using (XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream, null, null, false)) { dictionaryWriter.WriteStartElement("Properties"); foreach (KeyValuePair property in propertyBag) { dictionaryWriter.WriteStartElement("Property"); this.serializer.WriteObject(dictionaryWriter, property); dictionaryWriter.WriteEndElement(); } dictionaryWriter.WriteEndElement(); } } protected virtual void SerializeValue(Stream stream, object value) { using (XmlDictionaryWriter dictionaryWriter = XmlDictionaryWriter.CreateBinaryWriter(stream, null, null, false)) { this.serializer.WriteObject(dictionaryWriter, value); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- RegionInfo.cs
- InputLanguageEventArgs.cs
- SchemaCollectionPreprocessor.cs
- FlowDocumentView.cs
- RtfControlWordInfo.cs
- FontFamily.cs
- ChineseLunisolarCalendar.cs
- ErrorActivity.cs
- ServiceXNameTypeConverter.cs
- WebBrowserEvent.cs
- GreenMethods.cs
- AxisAngleRotation3D.cs
- FormViewRow.cs
- SchemaManager.cs
- SignatureHelper.cs
- LinkedResourceCollection.cs
- QueuedDeliveryRequirementsMode.cs
- WithParamAction.cs
- DataGridViewToolTip.cs
- UrlMappingsModule.cs
- GACMembershipCondition.cs
- DefaultAsyncDataDispatcher.cs
- PseudoWebRequest.cs
- BitmapDownload.cs
- HttpListenerResponse.cs
- MD5.cs
- Quad.cs
- TraceHandlerErrorFormatter.cs
- HandledEventArgs.cs
- NativeMethods.cs
- ExponentialEase.cs
- ToolStripContentPanel.cs
- XPathChildIterator.cs
- PatternMatcher.cs
- FactoryId.cs
- PropertyFilter.cs
- Application.cs
- JapaneseLunisolarCalendar.cs
- basevalidator.cs
- BrowserDefinition.cs
- Serializer.cs
- KeyboardDevice.cs
- ReflectTypeDescriptionProvider.cs
- ObjectToken.cs
- AppSettingsExpressionBuilder.cs
- LocatorBase.cs
- RunClient.cs
- ServiceBuildProvider.cs
- PerformanceCounters.cs
- ResXFileRef.cs
- CellTreeSimplifier.cs
- ControlHelper.cs
- WorkflowPageSetupDialog.cs
- WebPartConnectionsDisconnectVerb.cs
- InertiaExpansionBehavior.cs
- WebPartPersonalization.cs
- DragCompletedEventArgs.cs
- recordstatescratchpad.cs
- EventRoute.cs
- EpmSyndicationContentSerializer.cs
- StyleSelector.cs
- TextEffectCollection.cs
- ReferenceService.cs
- NavigationPropertyEmitter.cs
- ServiceAppDomainAssociationProvider.cs
- ClientApiGenerator.cs
- ChainOfResponsibility.cs
- DigitalSignature.cs
- StateBag.cs
- DockAndAnchorLayout.cs
- Drawing.cs
- securitymgrsite.cs
- OlePropertyStructs.cs
- ListViewSortEventArgs.cs
- TableSectionStyle.cs
- CurrentChangingEventArgs.cs
- RotateTransform.cs
- BaseTypeViewSchema.cs
- ExpressionNode.cs
- CommonDialog.cs
- StreamAsIStream.cs
- CacheChildrenQuery.cs
- _UncName.cs
- HtmlObjectListAdapter.cs
- UIPropertyMetadata.cs
- BinaryWriter.cs
- Graphics.cs
- TrackPointCollection.cs
- InheritanceAttribute.cs
- ScriptingWebServicesSectionGroup.cs
- InkCanvas.cs
- TemplateColumn.cs
- EventSetterHandlerConverter.cs
- EncoderReplacementFallback.cs
- LineSegment.cs
- Compilation.cs
- HostExecutionContextManager.cs
- CountdownEvent.cs
- SimpleMailWebEventProvider.cs
- Canvas.cs