public void Enumerate_EnumerableNonGenericType() { SinglyLinkedListKeyNode <int, int> list = null; list = list.Add(0, 1); list = list.Add(1, 2); list = list.Add(2, 3); int[] results = ((IEnumerable)list).OfType <int>().ToArray(); Assert.Equal(3, results.Length); Assert.Equal(3, results[0]); Assert.Equal(2, results[1]); Assert.Equal(1, results[2]); }
public void Enumerate_ConcreteType() { SinglyLinkedListKeyNode <int, int> list = null; list = list.Add(0, 1); list = list.Add(1, 2); list = list.Add(2, 3); int[] results = list.ToArray(); Assert.Equal(3, results.Length); Assert.Equal(3, results[0]); Assert.Equal(2, results[1]); Assert.Equal(1, results[2]); }
internal T GetOrAddScopedInstance <T>(Func <Scoped, T> factory, Type key) where T : notnull { SinglyLinkedListKeyNode <Type, object>?initialValue = _scopedInstances; SinglyLinkedListKeyNode <Type, object>?current = initialValue; while (current != null) { if (ReferenceEquals(current.Key, key)) { return((T)current.Value); } current = current.Next; } //There is a very slight chance that this instance is created more than once under heavy load. //In that case the duplicate will be discarded. T obj = factory(this); SinglyLinkedListKeyNode <Type, object> computedValue = initialValue.Add(key, obj); if (ReferenceEquals(Interlocked.CompareExchange(ref _scopedInstances, computedValue, initialValue), initialValue)) { return(obj); } else { return(HandleScopeThreadCollision(obj, key)); } }