コード例 #1
0
        public void ShouldBeAbleToRemoveAnElementFromImmutableCollection()
        {
            var elements = new List <string> {
                "Element1", "Element2"
            };
            IImmutableCollection <String> immutableCollection    = new ImmutableCollection <String>(elements);
            IImmutableCollection <String> newImmutableCollection = immutableCollection.Remove("Element1");

            Assert.Equals(2, immutableCollection.Size());
            Assert.Equals(1, newImmutableCollection.Size());
        }
コード例 #2
0
        public void ShouldAddNewElementToImmutableCollection()
        {
            var elements = new List <string> {
                "Element1", "Element2"
            };
            IImmutableCollection <String> immutableCollection    = new ImmutableCollection <String>(elements);
            IImmutableCollection <String> newImmutableCollection = immutableCollection.Add("newElement");

            Assert.Equals(2, immutableCollection.Size());
            Assert.Equals(3, newImmutableCollection.Size());
        }
コード例 #3
0
        public TCollection CreateCollection <TCollection, TValue>(IEnumerable <TValue> values) where TCollection : IImmutableCollection <TValue>
        {
            IImmutableCollection <TValue> colleciton = Activator.CreateInstance <TCollection>();

            return((TCollection)values.Aggregate(colleciton, (current, value) => current.Add(value)));
        }