Code:
/ 4.0 / 4.0 / 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. //---------------------------------------------------------------- // 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
- Rect.cs
- Socket.cs
- DesignTimeParseData.cs
- CompilationSection.cs
- Ops.cs
- MsmqInputMessage.cs
- CodeTypeReference.cs
- _FtpDataStream.cs
- AlignmentXValidation.cs
- UInt64Storage.cs
- HashAlgorithm.cs
- ListViewInsertionMark.cs
- MessageSmuggler.cs
- Gdiplus.cs
- SelectionEditingBehavior.cs
- Brush.cs
- NetNamedPipeBindingCollectionElement.cs
- PassportAuthenticationEventArgs.cs
- FileUtil.cs
- SchemaName.cs
- Stopwatch.cs
- StrokeNodeEnumerator.cs
- PerfService.cs
- ReferencedType.cs
- GlobalizationAssembly.cs
- UnmanagedHandle.cs
- UnionCqlBlock.cs
- SimpleTypeResolver.cs
- ReflectTypeDescriptionProvider.cs
- EventBuilder.cs
- ToolboxItemLoader.cs
- ApplyTemplatesAction.cs
- SoapInteropTypes.cs
- AuthenticationConfig.cs
- PathFigureCollectionValueSerializer.cs
- PropertyMetadata.cs
- ReflectEventDescriptor.cs
- CharKeyFrameCollection.cs
- DefaultAutoFieldGenerator.cs
- ComponentGlyph.cs
- DirectoryRedirect.cs
- AnnotationResourceChangedEventArgs.cs
- PrivilegedConfigurationManager.cs
- KnownTypesHelper.cs
- Types.cs
- ScriptMethodAttribute.cs
- safesecurityhelperavalon.cs
- RadioButton.cs
- StackBuilderSink.cs
- _NegotiateClient.cs
- SortedSet.cs
- pingexception.cs
- Error.cs
- _IPv6Address.cs
- ListViewDeletedEventArgs.cs
- ParseNumbers.cs
- WorkflowApplicationAbortedEventArgs.cs
- RuntimeArgumentHandle.cs
- ProtocolViolationException.cs
- Visual3D.cs
- ProtocolsSection.cs
- RangeValuePattern.cs
- GetPageNumberCompletedEventArgs.cs
- PersianCalendar.cs
- GridSplitter.cs
- InitiatorSessionSymmetricTransportSecurityProtocol.cs
- Messages.cs
- HandlerMappingMemo.cs
- EditingMode.cs
- ConfigurationManager.cs
- ComponentChangedEvent.cs
- PrintDialog.cs
- MarkerProperties.cs
- SystemColors.cs
- QilPatternVisitor.cs
- GeneralTransformGroup.cs
- MatrixCamera.cs
- SecurityKeyType.cs
- WebPartConnectionsConnectVerb.cs
- TableAutomationPeer.cs
- BaseTemplateBuildProvider.cs
- Rotation3DAnimation.cs
- MailAddressCollection.cs
- MILUtilities.cs
- TextEditorMouse.cs
- EventMappingSettings.cs
- PageAsyncTaskManager.cs
- StatusBar.cs
- Claim.cs
- DispatchChannelSink.cs
- MessageLoggingFilterTraceRecord.cs
- OperationCanceledException.cs
- CorrelationResolver.cs
- OdbcUtils.cs
- CorrelationTokenTypeConvertor.cs
- HttpProtocolReflector.cs
- LinqDataSourceSelectEventArgs.cs
- HwndSourceParameters.cs
- ConfigurationLocationCollection.cs
- MultiBinding.cs