Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Serializer / GenericQueueSurrogate.cs / 1305376 / GenericQueueSurrogate.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 GenericQueueSurrogate internal sealed class GenericQueueSurrogate : ISerializationSurrogate { internal GenericQueueSurrogate() { } void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context) { if (!obj.GetType().IsGenericType || obj.GetType().GetGenericTypeDefinition() != typeof(Queue<>)) throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj"); Type[] args = obj.GetType().GetGenericArguments(); if (args.Length != 1) throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj"); ArrayList items = new ArrayList(obj as ICollection); if (items.Count == 1) info.AddValue("item", items[0]); else info.AddValue("items", items.ToArray()); info.AddValue("itemType", args[0]); info.SetType(typeof(GenericQRef)); } object ISerializationSurrogate.SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { return null; } #region GenericQRef [Serializable] private sealed class GenericQRef : IObjectReference, IDeserializationCallback { [OptionalField] private IList items = null; [OptionalField] private object item = null; private Type itemType = null; [NonSerialized] private object queue = null; Object IObjectReference.GetRealObject(StreamingContext context) { if (this.queue == null) { Type queueType = typeof(Queue).GetGenericTypeDefinition().MakeGenericType(itemType); this.queue = queueType.GetConstructor(Type.EmptyTypes).Invoke(null); } return this.queue; } void IDeserializationCallback.OnDeserialization(Object sender) { if (this.queue != null) { MethodInfo enqueueMethod = this.queue.GetType().GetMethod("Enqueue"); if (enqueueMethod == null) throw new NullReferenceException("enqueueMethod"); if (this.items != null) { for (int n = 0; n < items.Count; n++) enqueueMethod.Invoke(this.queue, new object[] { this.items[n] }); } else { enqueueMethod.Invoke(this.queue, new object[] { this.item }); } this.queue = null; } } } #endregion } #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 GenericQueueSurrogate internal sealed class GenericQueueSurrogate : ISerializationSurrogate { internal GenericQueueSurrogate() { } void ISerializationSurrogate.GetObjectData(object obj, SerializationInfo info, StreamingContext context) { if (!obj.GetType().IsGenericType || obj.GetType().GetGenericTypeDefinition() != typeof(Queue<>)) throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj"); Type[] args = obj.GetType().GetGenericArguments(); if (args.Length != 1) throw new ArgumentException(SR.GetString(SR.Error_InvalidArgumentValue), "obj"); ArrayList items = new ArrayList(obj as ICollection); if (items.Count == 1) info.AddValue("item", items[0]); else info.AddValue("items", items.ToArray()); info.AddValue("itemType", args[0]); info.SetType(typeof(GenericQRef)); } object ISerializationSurrogate.SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector) { return null; } #region GenericQRef [Serializable] private sealed class GenericQRef : IObjectReference, IDeserializationCallback { [OptionalField] private IList items = null; [OptionalField] private object item = null; private Type itemType = null; [NonSerialized] private object queue = null; Object IObjectReference.GetRealObject(StreamingContext context) { if (this.queue == null) { Type queueType = typeof(Queue ).GetGenericTypeDefinition().MakeGenericType(itemType); this.queue = queueType.GetConstructor(Type.EmptyTypes).Invoke(null); } return this.queue; } void IDeserializationCallback.OnDeserialization(Object sender) { if (this.queue != null) { MethodInfo enqueueMethod = this.queue.GetType().GetMethod("Enqueue"); if (enqueueMethod == null) throw new NullReferenceException("enqueueMethod"); if (this.items != null) { for (int n = 0; n < items.Count; n++) enqueueMethod.Invoke(this.queue, new object[] { this.items[n] }); } else { enqueueMethod.Invoke(this.queue, new object[] { this.item }); } this.queue = null; } } } #endregion } #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
- ToolStripSeparator.cs
- DoubleAnimationUsingPath.cs
- TriggerBase.cs
- LambdaCompiler.Generated.cs
- WebSysDefaultValueAttribute.cs
- XmlUtil.cs
- CustomValidator.cs
- Timer.cs
- VectorAnimationUsingKeyFrames.cs
- UserValidatedEventArgs.cs
- GZipStream.cs
- TraceSection.cs
- DetailsViewDeleteEventArgs.cs
- AddingNewEventArgs.cs
- SafeIUnknown.cs
- TextTreeRootTextBlock.cs
- PrintingPermissionAttribute.cs
- ControlEvent.cs
- EnumConverter.cs
- PrivacyNoticeBindingElement.cs
- SqlDataSourceCustomCommandPanel.cs
- ProfilePropertySettings.cs
- Configuration.cs
- CodeMemberEvent.cs
- LineBreakRecord.cs
- BamlTreeNode.cs
- InputLanguageManager.cs
- ToolstripProfessionalRenderer.cs
- StateChangeEvent.cs
- ValidationHelper.cs
- XmlElementAttribute.cs
- BamlWriter.cs
- StsCommunicationException.cs
- UriSection.cs
- Point3DCollection.cs
- DataViewSetting.cs
- WinFormsUtils.cs
- DataGridViewRowPrePaintEventArgs.cs
- GeometryCombineModeValidation.cs
- MailHeaderInfo.cs
- PageThemeParser.cs
- RemoveStoryboard.cs
- StringCollection.cs
- DtdParser.cs
- LinkArea.cs
- CurrencyWrapper.cs
- WebPartsPersonalization.cs
- LookupBindingPropertiesAttribute.cs
- CustomLineCap.cs
- SymbolEqualComparer.cs
- FormViewRow.cs
- HandlerBase.cs
- EventLogRecord.cs
- LocalizableAttribute.cs
- AbstractSvcMapFileLoader.cs
- TableRowCollection.cs
- HttpCachePolicyElement.cs
- followingquery.cs
- TCPClient.cs
- ToolStripDropDownButton.cs
- ObjectDataSourceChooseTypePanel.cs
- ApplicationFileParser.cs
- Int64KeyFrameCollection.cs
- Membership.cs
- SqlDataSourceConfigureSortForm.cs
- ToolStripItemRenderEventArgs.cs
- TwoPhaseCommit.cs
- GridViewAutomationPeer.cs
- UnionCodeGroup.cs
- CodeBinaryOperatorExpression.cs
- EndOfStreamException.cs
- CompositeFontInfo.cs
- RepeaterItemCollection.cs
- IIS7WorkerRequest.cs
- BaseTreeIterator.cs
- XslCompiledTransform.cs
- TransactionWaitAsyncResult.cs
- CodeTypeDelegate.cs
- TransformCryptoHandle.cs
- WizardPanel.cs
- SetterBaseCollection.cs
- LockCookie.cs
- XpsFilter.cs
- SelectedDatesCollection.cs
- DelegateSerializationHolder.cs
- DataObject.cs
- JulianCalendar.cs
- ReflectionUtil.cs
- DataViewListener.cs
- PathFigureCollectionConverter.cs
- SolidColorBrush.cs
- WebPartConnection.cs
- IntermediatePolicyValidator.cs
- SmiMetaDataProperty.cs
- PolyBezierSegment.cs
- AssociationSetEnd.cs
- SafeEventHandle.cs
- SmiEventStream.cs
- FixedTextView.cs
- DataGridViewColumnHeaderCell.cs