Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / Model / CollectionChange.cs / 1305376 / CollectionChange.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.Model { using System.Runtime; class CollectionChange : ModelChange { public ModelItemCollection Collection { get; set; } public int Index { get; set; } public ModelItem Item { get; set; } public OperationType Operation { get; set; } public ModelTreeManager ModelTreeManager { get; set; } public override string Description { get { return this.Operation == OperationType.Insert ? SR.CollectionAddEditingScopeDescription : SR.CollectionRemoveEditingScopeDescription; } } public override bool Apply() { switch (this.Operation) { case OperationType.Insert: ApplyInsert(); break; case OperationType.Delete: ApplyDelete(); break; default: Fx.Assert("Operation should be Insert or Delete"); break; } return true; } private void ApplyDelete() { Fx.Assert(this.ModelTreeManager != null, "ModelTreeManager cannot be null."); Fx.Assert(this.Collection != null, "this.Collection cannot be null."); if (this.Index >= 0) { ((ModelItemCollectionImpl)this.Collection).RemoveAtCore(this.Index); } else { Fx.Assert(this.Index == -1, "-1 must be used to indicate Remove(item)"); this.Index = this.Collection.IndexOf(this.Item); ((ModelItemCollectionImpl)this.Collection).RemoveCore(this.Item); } // if no more this.Item exists in this.Collection, then this.Item should be released from the ModelTree. if (this.Collection.IndexOf(this.Item) == -1) { ((IModelTreeItem)this.Item).RemoveParent(this.Collection); this.ModelTreeManager.ReleaseModelItem(this.Item, this.Collection); } this.ModelTreeManager.NotifyCollectionRemove(this.Item); } private void ApplyInsert() { Fx.Assert(this.ModelTreeManager != null, "ModelTreeManager cannot be null."); Fx.Assert(this.Collection != null, "this.Collection cannot be null."); this.ModelTreeManager.ReAddModelItemToModelTree(this.Item); if (this.Index >= 0) { ((ModelItemCollectionImpl)this.Collection).InsertCore(this.Index, this.Item); } else { Fx.Assert(this.Index == -1, "-1 must be used to indicate Add(item)"); this.Index = this.Collection.Count; ((ModelItemCollectionImpl)this.Collection).AddCore(this.Item); } this.ModelTreeManager.NotifyCollectionInsert(this.Item); } public override Change GetInverse() { OperationType reverseOperation = this.Operation == OperationType.Insert ? OperationType.Delete : OperationType.Insert; return new CollectionChange() { Collection = this.Collection, Operation = reverseOperation, Item = this.Item, ModelTreeManager = this.ModelTreeManager, Index = this.Index }; } public enum OperationType { Insert, Delete } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DocumentPropertiesDialog.cs
- X509SecurityTokenProvider.cs
- RoleGroupCollection.cs
- NameValueFileSectionHandler.cs
- MediaEntryAttribute.cs
- ButtonStandardAdapter.cs
- RtfFormatStack.cs
- BaseCodeDomTreeGenerator.cs
- RTLAwareMessageBox.cs
- HtmlImage.cs
- XmlSerializerVersionAttribute.cs
- wmiprovider.cs
- NotificationContext.cs
- WorkflowDefinitionContext.cs
- DetailsViewModeEventArgs.cs
- VariableElement.cs
- UserInitiatedRoutedEventPermissionAttribute.cs
- BooleanProjectedSlot.cs
- BamlLocalizationDictionary.cs
- ExpressionNormalizer.cs
- TypedDatasetGenerator.cs
- DataListCommandEventArgs.cs
- ListViewDeletedEventArgs.cs
- JulianCalendar.cs
- ViewGenResults.cs
- EncodingInfo.cs
- PageHandlerFactory.cs
- MetafileEditor.cs
- PageTheme.cs
- InstanceCreationEditor.cs
- IntranetCredentialPolicy.cs
- XPathNavigator.cs
- LongPath.cs
- XsltOutput.cs
- PointAnimation.cs
- SiteOfOriginPart.cs
- TaskResultSetter.cs
- CacheAxisQuery.cs
- X509Chain.cs
- TypeForwardedToAttribute.cs
- PackageRelationship.cs
- StackOverflowException.cs
- HMACSHA256.cs
- AssemblyBuilder.cs
- DbConvert.cs
- RegistrySecurity.cs
- Label.cs
- RefreshPropertiesAttribute.cs
- DisposableCollectionWrapper.cs
- PhysicalOps.cs
- IndexingContentUnit.cs
- WebAdminConfigurationHelper.cs
- ScriptHandlerFactory.cs
- CatalogPartCollection.cs
- QueueProcessor.cs
- DeobfuscatingStream.cs
- streamingZipPartStream.cs
- RelationshipEndMember.cs
- UdpSocket.cs
- ConsumerConnectionPointCollection.cs
- Imaging.cs
- DesignParameter.cs
- AlgoModule.cs
- _SpnDictionary.cs
- SafeFindHandle.cs
- TabPanel.cs
- Opcode.cs
- TextEditorTyping.cs
- WebBrowser.cs
- DependencyProperty.cs
- NamespaceCollection.cs
- Command.cs
- Preprocessor.cs
- UnsafeNativeMethods.cs
- HttpClientProtocol.cs
- OleDbStruct.cs
- DataGridViewColumn.cs
- ToolStripTextBox.cs
- EventSinkActivity.cs
- Rijndael.cs
- BufferedGraphicsManager.cs
- VerificationAttribute.cs
- SizeAnimationClockResource.cs
- Content.cs
- UpdatePanel.cs
- PictureBox.cs
- ProfileSettingsCollection.cs
- CreationContext.cs
- Configuration.cs
- EditBehavior.cs
- SamlDoNotCacheCondition.cs
- ShortcutKeysEditor.cs
- CFStream.cs
- OleDbFactory.cs
- CollectionViewSource.cs
- EditorZone.cs
- StylusPointDescription.cs
- CompiledIdentityConstraint.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- WebSysDisplayNameAttribute.cs