Ejemplo n.º 1
0
        /// <summary>
        /// Returns a duplicate of this entire list, where each item has been cloned
        /// if it implements ICloneable. Otherwise, the values will be a shallow copy.
        /// </summary>
        /// <returns>The clone.</returns>
        public object Clone()
        {
            CopyList <T> result = MemberwiseClone() as CopyList <T>;

            OnCopy(result);
            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Occurs during the copy process and overrides the base behavior so that events are suspended.
        /// </summary>
        /// <param name="copy">The copy.</param>
        protected override void OnCopy(CopyList <T> copy)
        {
            ChangeEventList <T> myCopy = copy as ChangeEventList <T>;

            if (myCopy != null)
            {
                RemoveHandlers(myCopy);
                myCopy.SuspendEvents();
            }

            base.OnCopy(copy);
            myCopy?.ResumeEvents();
        }
Ejemplo n.º 3
0
 /// <summary>
 /// This copies any individual members of the list. If the item can be
 /// cloned, then it copies the cloned item. Otherwise it copies the regular item.
 /// This method can be overridden to handle special behavior in sub-classes.
 /// </summary>
 /// <param name="copy">The copy.</param>
 protected virtual void OnCopy(CopyList <T> copy)
 {
     copy.InnerList = new List <T>();
     foreach (T item in InnerList)
     {
         ICloneable c = Global.SafeCastTo <ICloneable>(item);
         if (c != null)
         {
             T value = Global.SafeCastTo <T>(c.Clone());
             copy.Add(value);
         }
         else
         {
             copy.Add(item);
         }
     }
 }