Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Serializer / CollectionMarkupSerializer.cs / 1305376 / CollectionMarkupSerializer.cs
namespace System.Workflow.ComponentModel.Serialization { using System; using System.IO; using System.CodeDom; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Collections; using System.Xml; using System.Xml.Serialization; using System.Reflection; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Globalization; using System.Workflow.ComponentModel.Compiler; using System.Workflow.ComponentModel.Design; using System.Runtime.Serialization; using System.Security.Permissions; using System.Collections.ObjectModel; using System.Drawing; #region Class CollectionMarkupSerializer internal class CollectionMarkupSerializer : WorkflowMarkupSerializer { protected internal override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj) { if (obj == null) throw new ArgumentNullException("obj"); if (!IsValidCollectionType(obj.GetType())) throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); IEnumerable enumerable = obj as IEnumerable; ArrayList arrayList = new ArrayList(); foreach (object containedObj in enumerable) arrayList.Add(containedObj); return arrayList; } protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj) { return new PropertyInfo[] { }; } protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializationManager serializationManager, object value) { if (value == null) return false; if (!IsValidCollectionType(value.GetType())) throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, value.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); IEnumerable enumerable = value as IEnumerable; foreach (object obj in enumerable) return true; return false; } protected internal override void ClearChildren(WorkflowMarkupSerializationManager serializationManager, object obj) { if (obj == null) throw new ArgumentNullException("obj"); if (!IsValidCollectionType(obj.GetType())) throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); ICollection collection = obj as ICollection; if (collection == null) obj.GetType().InvokeMember("Clear", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj, new object[] {}, CultureInfo.InvariantCulture); } protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object parentObj, object childObj) { if (parentObj == null) throw new ArgumentNullException("parentObj"); if (!IsValidCollectionType(parentObj.GetType())) throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, parentObj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); parentObj.GetType().InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, parentObj, new object[] { childObj }, CultureInfo.InvariantCulture); } internal static bool IsValidCollectionType(Type collectionType) { if (collectionType == null) return false; if (typeof(Array).IsAssignableFrom(collectionType)) return false; return (typeof(ICollection).IsAssignableFrom(collectionType) || (collectionType.IsGenericType && (typeof(ICollection<>).IsAssignableFrom(collectionType.GetGenericTypeDefinition()) || typeof(IList<>).IsAssignableFrom(collectionType.GetGenericTypeDefinition())))); } } #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.IO; using System.CodeDom; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Collections; using System.Xml; using System.Xml.Serialization; using System.Reflection; using System.Collections.Generic; using System.Diagnostics; using System.Text; using System.Globalization; using System.Workflow.ComponentModel.Compiler; using System.Workflow.ComponentModel.Design; using System.Runtime.Serialization; using System.Security.Permissions; using System.Collections.ObjectModel; using System.Drawing; #region Class CollectionMarkupSerializer internal class CollectionMarkupSerializer : WorkflowMarkupSerializer { protected internal override IList GetChildren(WorkflowMarkupSerializationManager serializationManager, object obj) { if (obj == null) throw new ArgumentNullException("obj"); if (!IsValidCollectionType(obj.GetType())) throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); IEnumerable enumerable = obj as IEnumerable; ArrayList arrayList = new ArrayList(); foreach (object containedObj in enumerable) arrayList.Add(containedObj); return arrayList; } protected internal override PropertyInfo[] GetProperties(WorkflowMarkupSerializationManager serializationManager, object obj) { return new PropertyInfo[] { }; } protected internal override bool ShouldSerializeValue(WorkflowMarkupSerializationManager serializationManager, object value) { if (value == null) return false; if (!IsValidCollectionType(value.GetType())) throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, value.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); IEnumerable enumerable = value as IEnumerable; foreach (object obj in enumerable) return true; return false; } protected internal override void ClearChildren(WorkflowMarkupSerializationManager serializationManager, object obj) { if (obj == null) throw new ArgumentNullException("obj"); if (!IsValidCollectionType(obj.GetType())) throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, obj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); ICollection collection = obj as ICollection; if (collection == null) obj.GetType().InvokeMember("Clear", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, obj, new object[] {}, CultureInfo.InvariantCulture); } protected internal override void AddChild(WorkflowMarkupSerializationManager serializationManager, object parentObj, object childObj) { if (parentObj == null) throw new ArgumentNullException("parentObj"); if (!IsValidCollectionType(parentObj.GetType())) throw new Exception(SR.GetString(SR.Error_SerializerTypeRequirement, parentObj.GetType().FullName, typeof(ICollection).FullName, typeof(ICollection<>).FullName)); parentObj.GetType().InvokeMember("Add", BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Instance, null, parentObj, new object[] { childObj }, CultureInfo.InvariantCulture); } internal static bool IsValidCollectionType(Type collectionType) { if (collectionType == null) return false; if (typeof(Array).IsAssignableFrom(collectionType)) return false; return (typeof(ICollection).IsAssignableFrom(collectionType) || (collectionType.IsGenericType && (typeof(ICollection<>).IsAssignableFrom(collectionType.GetGenericTypeDefinition()) || typeof(IList<>).IsAssignableFrom(collectionType.GetGenericTypeDefinition())))); } } #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
- PasswordBoxAutomationPeer.cs
- ListBoxItem.cs
- PropertyTabChangedEvent.cs
- QueueSurrogate.cs
- LinkedResource.cs
- TickBar.cs
- ConstraintCollection.cs
- MarginsConverter.cs
- StylusSystemGestureEventArgs.cs
- HttpCookiesSection.cs
- CharEntityEncoderFallback.cs
- FixedHighlight.cs
- ColorAnimationUsingKeyFrames.cs
- GenericRootAutomationPeer.cs
- CertificateReferenceElement.cs
- GridViewSelectEventArgs.cs
- SrgsOneOf.cs
- NopReturnReader.cs
- SoapEnvelopeProcessingElement.cs
- SplineKeyFrames.cs
- ConfigXmlAttribute.cs
- InputQueueChannel.cs
- ButtonField.cs
- XmlElementList.cs
- TimeSpanValidatorAttribute.cs
- QilValidationVisitor.cs
- EncryptedReference.cs
- HttpCapabilitiesEvaluator.cs
- Assembly.cs
- SendMessageRecord.cs
- ValueConversionAttribute.cs
- ModulesEntry.cs
- SHA1CryptoServiceProvider.cs
- ActivationArguments.cs
- Bezier.cs
- CommonXSendMessage.cs
- GiveFeedbackEvent.cs
- ActivatedMessageQueue.cs
- ProfilePropertySettingsCollection.cs
- GeometryDrawing.cs
- GroupBoxRenderer.cs
- StateDesigner.Helpers.cs
- DependencyPropertyConverter.cs
- StrokeIntersection.cs
- RightsManagementEncryptedStream.cs
- MailMessageEventArgs.cs
- MarkupProperty.cs
- SqlSelectStatement.cs
- Table.cs
- WmlTextViewAdapter.cs
- DataGridViewRowHeaderCell.cs
- FileInfo.cs
- PointAnimationUsingPath.cs
- ComplexPropertyEntry.cs
- XmlBoundElement.cs
- DashStyles.cs
- TimelineGroup.cs
- ObjectDataSourceSelectingEventArgs.cs
- CharacterShapingProperties.cs
- BitmapEffect.cs
- ViewStateException.cs
- AlternateViewCollection.cs
- SmiXetterAccessMap.cs
- QueryReaderSettings.cs
- sitestring.cs
- SystemIPv4InterfaceProperties.cs
- XmlSchemaSimpleTypeUnion.cs
- _ReceiveMessageOverlappedAsyncResult.cs
- ButtonField.cs
- OleDbTransaction.cs
- GridPatternIdentifiers.cs
- DrawListViewColumnHeaderEventArgs.cs
- ThumbButtonInfo.cs
- MultipartIdentifier.cs
- IntellisenseTextBox.designer.cs
- ResizeGrip.cs
- AccessDataSourceView.cs
- ToolStripDropDown.cs
- AttachedPropertyBrowsableForChildrenAttribute.cs
- TableRow.cs
- HttpWebRequestElement.cs
- PointAnimationUsingPath.cs
- ObjectDataSource.cs
- HttpModuleAction.cs
- VirtualizingPanel.cs
- filewebrequest.cs
- DelegateInArgument.cs
- SqlParameter.cs
- HttpValueCollection.cs
- PageTheme.cs
- ListSortDescriptionCollection.cs
- VisualStyleInformation.cs
- FacetDescriptionElement.cs
- SQLInt32Storage.cs
- FigureParaClient.cs
- WebBrowserPermission.cs
- SqlGatherProducedAliases.cs
- GeneralTransform3DGroup.cs
- ZipIOExtraFieldPaddingElement.cs
- FactoryMaker.cs