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
- GenerateScriptTypeAttribute.cs
- MexServiceChannelBuilder.cs
- BinaryFormatterWriter.cs
- OpenTypeCommon.cs
- HtmlCommandAdapter.cs
- PropertyValueChangedEvent.cs
- DbMetaDataCollectionNames.cs
- CompositeCollection.cs
- OLEDB_Util.cs
- CompiledRegexRunner.cs
- DefaultValidator.cs
- QilXmlReader.cs
- _DisconnectOverlappedAsyncResult.cs
- BinaryObjectInfo.cs
- CommonGetThemePartSize.cs
- StringUtil.cs
- WebPartUtil.cs
- ZipIOCentralDirectoryFileHeader.cs
- DataColumn.cs
- CodeNamespaceCollection.cs
- TextureBrush.cs
- AddInActivator.cs
- CreateDataSourceDialog.cs
- Menu.cs
- EventSetter.cs
- WebPartConnectionsConfigureVerb.cs
- OperationAbortedException.cs
- XmlSchemaExternal.cs
- CultureTable.cs
- InputLangChangeEvent.cs
- DataSpaceManager.cs
- ForEachAction.cs
- XPathNodePointer.cs
- AsyncCompletedEventArgs.cs
- ObjectViewListener.cs
- _Connection.cs
- Point3DAnimationBase.cs
- DataBinding.cs
- AnimationTimeline.cs
- CharEnumerator.cs
- TypeUtil.cs
- HostVisual.cs
- ContentPlaceHolder.cs
- ActivationServices.cs
- CancelRequestedQuery.cs
- MimeMultiPart.cs
- QilExpression.cs
- DataContext.cs
- XmlSchemaSimpleContentRestriction.cs
- FixedFindEngine.cs
- IgnoreFlushAndCloseStream.cs
- XhtmlBasicControlAdapter.cs
- DesignerForm.cs
- HostExecutionContextManager.cs
- RegexCode.cs
- TemplateInstanceAttribute.cs
- ToolStripStatusLabel.cs
- MdImport.cs
- Permission.cs
- DataServiceEntityAttribute.cs
- MarshalByRefObject.cs
- DataControlPagerLinkButton.cs
- QueryCacheManager.cs
- BinHexDecoder.cs
- AnonymousIdentificationSection.cs
- FormatException.cs
- LinqToSqlWrapper.cs
- SafeUserTokenHandle.cs
- ContractTypeNameCollection.cs
- NamespaceCollection.cs
- InputLanguageSource.cs
- CompoundFileDeflateTransform.cs
- RuntimeWrappedException.cs
- XXXInfos.cs
- relpropertyhelper.cs
- EventLogTraceListener.cs
- FormsAuthenticationEventArgs.cs
- SHA512Managed.cs
- RadioButtonList.cs
- SequenceDesigner.cs
- DictionaryChange.cs
- CodeAttributeArgument.cs
- KnownAssembliesSet.cs
- EntityDataSourceChangedEventArgs.cs
- XsltContext.cs
- TrackingCondition.cs
- XamlGridLengthSerializer.cs
- LeaseManager.cs
- DataControlLinkButton.cs
- SectionVisual.cs
- ResourceExpression.cs
- BufferAllocator.cs
- TextLineBreak.cs
- DragCompletedEventArgs.cs
- Attachment.cs
- SchemaCollectionPreprocessor.cs
- Missing.cs
- ZipIOCentralDirectoryBlock.cs
- ComboBox.cs
- FormViewRow.cs