示例#1
0
        public void MoveToFront(T item)
        {
            var removed = Remove(item);

            Asrt.True(removed, "Item must be present to move it.");
            AddToFront(item);
        }
示例#2
0
        public Snapshot CreateSnapshot()
        {
            LogFile.Debug("Create snapshot.");
            Asrt.True(_isEnabled, "Tracker is disabled, did you forget to enable it?");

            return(new Snapshot(_changeHistory.Count));
        }
示例#3
0
            private static void Fail()
            {
                var enable = (bool?)CallContext.GetData(EnableKey);

                if (enable != true)
                {
                    return;
                }

                Asrt.Fail("Usage of a non initialized Trackable<> or TrackableList<> detected!");
            }
示例#4
0
        public void RollbackToSnapshot(Snapshot snapshot)
        {
            LogFile.Debug("Restore from snapshot.");
            Asrt.True(_isEnabled, "Tracker is disabled, did you forget to enable it?");

            while (_changeHistory.Count > snapshot.History)
            {
                var action = _changeHistory.Pop();
                action();
            }
        }
示例#5
0
        public void Disable()
        {
            Asrt.True(_changeHistory.Count == 0,
                      String.Format(
                          "Disabling a change tracker with history ({0}) is not allowed. This is a common indication of an incorrect object copy.",
                          _changeHistory.Count));

            _isEnabled = false;
            _changeHistory.Clear();
            Guard.Disable();
        }
示例#6
0
        public static IList <T> ShuffleInPlace <T>(this IList <T> list, IList <int> permutation)
        {
            Asrt.True(permutation.Count == list.Count,
                      "Permutation and list must be of equal lenghts.");

            var listCopy = list.ToArray();

            for (var i = 0; i < permutation.Count; i++)
            {
                list[permutation[i]] = listCopy[i];
            }
            return(list);
        }
示例#7
0
            public ParameterlessCtor GetCtor(Type type)
            {
                lock (_ctorLock)
                {
                    ParameterlessCtor ctor;
                    if (_ctors.TryGetValue(type, out ctor) == false)
                    {
                        ctor = type.GetParameterlessCtor();

                        Asrt.True(ctor != null,
                                  String.Format("Type {0} is marked with [Copyable] but is missing a parameterless constructor.", type));

                        _ctors.Add(type, ctor);
                    }

                    return(ctor);
                }
            }
示例#8
0
 private void AssertNotLocked()
 {
     Asrt.True(!_isLocked,
               "Trying to modify a locked change tracker. This is a common indication of an incorrect object copy.");
 }