Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DefaultHttpHandler.cs
- ThreadStartException.cs
- DLinqDataModelProvider.cs
- VarInfo.cs
- RectAnimation.cs
- ObjectPersistData.cs
- NameValueSectionHandler.cs
- AssociatedControlConverter.cs
- RC2.cs
- Activity.cs
- RemoteWebConfigurationHostStream.cs
- WebBrowsableAttribute.cs
- ProfessionalColors.cs
- DoubleAnimation.cs
- SqlFormatter.cs
- FullTextLine.cs
- GACMembershipCondition.cs
- SmiEventSink.cs
- DataGridColumnHeaderAutomationPeer.cs
- GenericTypeParameterBuilder.cs
- MethodToken.cs
- PropertyHelper.cs
- SourceLineInfo.cs
- CaseInsensitiveComparer.cs
- CustomError.cs
- LocalizableAttribute.cs
- BamlRecordReader.cs
- ExtensionDataObject.cs
- Soap.cs
- WebZone.cs
- SoapIncludeAttribute.cs
- WebPartManager.cs
- DragEvent.cs
- FontUnitConverter.cs
- DataGridViewRow.cs
- SharedPersonalizationStateInfo.cs
- EntityDataSourceWizardForm.cs
- SvcMapFileLoader.cs
- TimelineClockCollection.cs
- ToolStripInSituService.cs
- SafeProcessHandle.cs
- AddInStore.cs
- XPathParser.cs
- XsltQilFactory.cs
- ImageFormat.cs
- FormsAuthenticationCredentials.cs
- NetworkInformationException.cs
- WebServiceErrorEvent.cs
- CookielessHelper.cs
- CodeSnippetStatement.cs
- PointLight.cs
- KnownBoxes.cs
- NameValueSectionHandler.cs
- SecurityTokenAttachmentMode.cs
- PageCatalogPartDesigner.cs
- ModelPerspective.cs
- StrongNamePublicKeyBlob.cs
- OdbcErrorCollection.cs
- KnownBoxes.cs
- SqlTriggerContext.cs
- ChangesetResponse.cs
- SessionIDManager.cs
- EventProviderWriter.cs
- DataGridSortingEventArgs.cs
- WizardDesigner.cs
- HttpApplicationFactory.cs
- GridView.cs
- LayoutEvent.cs
- Executor.cs
- EncodingInfo.cs
- DeflateEmulationStream.cs
- HttpRuntime.cs
- SizeConverter.cs
- EncoderFallback.cs
- InvalidContentTypeException.cs
- SQLInt16.cs
- TrackingProvider.cs
- Profiler.cs
- TextDecoration.cs
- XamlBrushSerializer.cs
- ProcessHostConfigUtils.cs
- RealizationDrawingContextWalker.cs
- WebBrowser.cs
- serverconfig.cs
- PerformanceCountersElement.cs
- UInt64Converter.cs
- WebScriptEnablingElement.cs
- UTF32Encoding.cs
- CompilerTypeWithParams.cs
- ValidationException.cs
- KnownAssemblyEntry.cs
- ListManagerBindingsCollection.cs
- SmtpNtlmAuthenticationModule.cs
- TypeDescriptor.cs
- EdmFunction.cs
- _CommandStream.cs
- FixedHighlight.cs
- DataKey.cs
- CatalogZone.cs
- ConfigurationElementCollection.cs