AK.F1.Timing.Model.Collections.PostedTimeCollectionModel.ReplaceCurrent C# (CSharp) Метод

ReplaceCurrent() публичный Метод

Replaces the current item with the specified replacement.
/// Thrown when is . /// /// Thrown when the collection is empty. ///
public ReplaceCurrent ( PostedTime replacement ) : void
replacement PostedTime The replacement item.
Результат void
        public void ReplaceCurrent(PostedTime replacement)
        {
            Guard.NotNull(replacement, "replacement");
            if(InnerItems.Count == 0)
            {
                throw Guard.PostedTimeCollectionModel_CurrentCannotBeReplaced();
            }

            InnerItems[InnerItems.Count - 1] = replacement;
            ReplaceCurrentStatistics(replacement);
        }

Usage Example

        public void replacing_an_item_updates_the_range()
        {
            var model = new PostedTimeCollectionModel();
            var observer = model.CreateObserver();

            model.Add(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(0), model.Range);
            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(0), model.Range);
            model.Add(PT(20, PostedTimeType.Normal, 1));
            model.ReplaceCurrent(PT(10, PostedTimeType.Normal, 1));
            Assert.Equal(TS(10), model.Range);

            Assert.Equal(2, observer.GetChangeCount(x => x.Range));
        }
All Usage Examples Of AK.F1.Timing.Model.Collections.PostedTimeCollectionModel::ReplaceCurrent