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
- StateManagedCollection.cs
- HMACSHA384.cs
- COM2FontConverter.cs
- SecurityHelper.cs
- SerialPinChanges.cs
- CmsInterop.cs
- grammarelement.cs
- RoutedUICommand.cs
- DataGridSortingEventArgs.cs
- SettingsAttributeDictionary.cs
- keycontainerpermission.cs
- TreeViewDesigner.cs
- Pts.cs
- DynamicDataRouteHandler.cs
- PinnedBufferMemoryStream.cs
- TrustLevel.cs
- EventEntry.cs
- WebSysDefaultValueAttribute.cs
- SchemaManager.cs
- WebGetAttribute.cs
- DesignerSerializerAttribute.cs
- SystemIcmpV6Statistics.cs
- BitStack.cs
- WindowsRebar.cs
- CmsInterop.cs
- CommandEventArgs.cs
- KeyConverter.cs
- PeerFlooder.cs
- MeshGeometry3D.cs
- ObjectQuery_EntitySqlExtensions.cs
- ButtonBaseAutomationPeer.cs
- ColorPalette.cs
- HotCommands.cs
- LocatorBase.cs
- Point3DAnimation.cs
- GetPageCompletedEventArgs.cs
- SizeAnimationClockResource.cs
- SerializationFieldInfo.cs
- SessionStateModule.cs
- XmlIgnoreAttribute.cs
- DetailsViewInsertEventArgs.cs
- EntityKeyElement.cs
- LocalIdCollection.cs
- Positioning.cs
- TypeGeneratedEventArgs.cs
- AffineTransform3D.cs
- NullableLongAverageAggregationOperator.cs
- MenuAutoFormat.cs
- CallSiteBinder.cs
- MenuItemBindingCollection.cs
- SharedPerformanceCounter.cs
- ToolStripContainerActionList.cs
- ConnectionProviderAttribute.cs
- FixedSOMContainer.cs
- VarRefManager.cs
- EllipticalNodeOperations.cs
- RowBinding.cs
- SoundPlayerAction.cs
- ExpressionBuilder.cs
- SafeSecurityHelper.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- HttpModuleAction.cs
- GetPageCompletedEventArgs.cs
- ModelFunction.cs
- SoapFault.cs
- WebPartEditorOkVerb.cs
- EncoderReplacementFallback.cs
- ProjectionCamera.cs
- SettingsPropertyValue.cs
- AssociationSet.cs
- WebPartCatalogCloseVerb.cs
- CorrelationActionMessageFilter.cs
- BindingGroup.cs
- GeneralTransform2DTo3DTo2D.cs
- ProxyManager.cs
- XamlVector3DCollectionSerializer.cs
- ControlAdapter.cs
- DataGridViewColumnConverter.cs
- RuntimeResourceSet.cs
- PropertyItem.cs
- XmlIgnoreAttribute.cs
- CompatibleComparer.cs
- CharEnumerator.cs
- TablePatternIdentifiers.cs
- XmlNodeChangedEventManager.cs
- SolidBrush.cs
- NetCodeGroup.cs
- WinOEToolBoxItem.cs
- BrushConverter.cs
- GlobalizationSection.cs
- NominalTypeEliminator.cs
- PreservationFileReader.cs
- RenamedEventArgs.cs
- SecurityTokenException.cs
- XmlSchemaComplexContentRestriction.cs
- TrustExchangeException.cs
- FreezableCollection.cs
- FrameworkObject.cs
- SQLStringStorage.cs
- Hex.cs