Beispiel #1
0
 public void TestNotACollection()
 {
     Assert.Expect(
         typeof(ArgumentException),
         delegate { CollectionInitializer.For(10); }
         );
 }
Beispiel #2
0
        public virtual void Write(IWriteContext context, object obj)
        {
            ICollectionInitializer initializer = CollectionInitializer.For(obj);
            IEnumerable            enumerable  = (IEnumerable)obj;
            ClassMetadata          elementType = DetectElementTypeErasingNullables(Container(context), enumerable);

            WriteElementTypeHandlerId(context, elementType);
            WriteElementCount(context, initializer);
            WriteElements(context, enumerable, elementType.TypeHandler());
        }
Beispiel #3
0
        public virtual void Activate(IReferenceActivationContext context)
        {
            object collection = context.PersistentObject();
            ICollectionInitializer initializer = CollectionInitializer.For(collection);

            initializer.Clear();

            ReadElements(context, initializer, ReadElementTypeHandler(context, context));

            initializer.FinishAdding();
        }
Beispiel #4
0
        private static void Fill(ICollection collection, IEnumerable <T> elements)
        {
            var initializer = CollectionInitializer.For(collection);

            foreach (var item in elements)
            {
                initializer.Add(item);
            }

            initializer.FinishAdding();
        }
Beispiel #5
0
        public object NewItem(object element)
        {
            var item = NewItem();

            var initializer = CollectionInitializer.For(CollectionFor(item));

            initializer.Add(element);
            initializer.FinishAdding();

            return(item);
        }
        public static void CopyCollectionState(object original, object destination, ICounterpartFinder counterpartFinder)
        {
            IEnumerable            originalCollection    = (IEnumerable )original;
            ICollectionInitializer destinationCollection = CollectionInitializer.For(destination);

            destinationCollection.Clear();

            foreach (object element in originalCollection)
            {
                object counterpart = counterpartFinder.FindCounterpart(element);
                destinationCollection.Add(counterpart);
            }
        }
        public void Test()
        {
            object list = new LinkedList <int>();
            ICollectionInitializer initializer = CollectionInitializer.For(list);

            Assert.IsNotNull(initializer);

            foreach (object item in Values)
            {
                initializer.Add(item);
            }

            initializer.FinishAdding();

            Iterator4Assert.AreEqual(Values, ((IEnumerable)list).GetEnumerator());
        }