示例#1
0
        /// <summary>
        /// Add strategy inspector
        /// </summary>
        /// <param name="inspector">inspector</param>
        public void AddInspector(IActivationStrategyInspector inspector)
        {
            ImmutableLinkedList.ThreadSafeAdd(ref Inspectors, inspector);

            foreach (var strategy in GetAllStrategies())
            {
                inspector.Inspect(strategy);
            }
        }
示例#2
0
        /// <summary>
        /// Add an object for disposal tracking
        /// </summary>
        /// <param name="disposable">disposable object to track</param>
        /// <param name="cleanupDelegate">logic that will be run directly before the object is disposed</param>
        public T AddDisposable <T>(T disposable, Action <T> cleanupDelegate = null) where T : IDisposable
        {
            Action cleanupAction = null;

            if (cleanupDelegate != null)
            {
                cleanupAction = () => cleanupDelegate(disposable);
            }

            ImmutableLinkedList.ThreadSafeAdd(ref _disposable,
                                              new Tuple <IDisposable, Action>(disposable, cleanupAction));

            return(disposable);
        }
示例#3
0
        public void ImmutableLinkedList_ThreadSafeAdd()
        {
            var list = ImmutableLinkedList <int> .Empty;

            ImmutableLinkedList.ThreadSafeAdd(ref list, 5);
            ImmutableLinkedList.ThreadSafeAdd(ref list, 10);
            ImmutableLinkedList.ThreadSafeAdd(ref list, 15);

            var newList = new List <int>(list);

            Assert.Equal(3, newList.Count);
            Assert.Contains(5, newList);
            Assert.Contains(10, newList);
            Assert.Contains(15, newList);
        }
示例#4
0
        private void AddRangeToList(int startValue)
        {
            _startEvent.WaitOne();

            for (var i = startValue; i < (startValue + _addAmount); i++)
            {
                ImmutableLinkedList.ThreadSafeAdd(ref _linkedList, i);

                if (_addAmount % 1000 == 0)
                {
                    Thread.Sleep(0);
                }
            }

            _countdownEvent.Signal();
        }
示例#5
0
        public void ImmutableLinkedList_Null_Reference_Check()
        {
            var value = (ImmutableLinkedList <int>)null;

            Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList.ThreadSafeAdd(ref value, 2));

            Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList.ThreadSafeEmpty(ref value));

            Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList.ThreadSafeAddRange(ref value, new[] { 5 }));

            value = ImmutableLinkedList <int> .Empty;

            Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList.ThreadSafeAddRange(ref value, null));

            Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList <int> .Empty.Visit(null));

            Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList <int> .Empty.AddRange(null));

            Assert.Throws <ArgumentNullException>(() => ImmutableLinkedList.From <int>(null));
        }