示例#1
0
        public static void Reset <T> (this ICollection <T> self, IEnumerable <T> newContents)
        {
            if (self == null)
            {
                throw new ArgumentNullException(nameof(self));
            }
            if (newContents == null)
            {
                throw new ArgumentNullException(nameof(newContents));
            }

            if (self is ObservableCollectionEx <T> oce)
            {
                oce.Reset(newContents);
            }
            else
            {
                self.Clear();
                self.AddItems(newContents);
            }
        }
 /// <summary>
 /// Adds the given new collection to a collection and returns the collection.
 /// </summary>
 /// <remarks>
 /// To be used as a preferred form to traditional collection Add when chaining is necessary or when updating an EF object tree.
 /// FOR EF: Usage of this method ensures object trees are populated in the correct order for persistence of IDs.
 /// </remarks>
 /// <typeparam name="T">The type of the object.</typeparam>
 /// <param name="this">The collection property for the collection to add to.</param>
 /// <param name="newObjects">The new object to add.</param>
 /// <returns>The collection.</returns>
 public static ICollection <T> AddItems <T>(this ICollection <T> @this, IEnumerable <T> newObjects)
 => @this.AddItems(newObjects.ToArray());