/// <summary> /// Creates a new object that is a copy of the current instance. /// </summary> /// <returns> /// A new object that is a copy of this instance. /// </returns> public object Clone( ) { CloneableCollection <T> result = new CloneableCollection <T> (); Type type = typeof(T); if (!type.IsValueType) { if (typeof(T).IsAssignableFrom(typeof(ICloneable))) { throw new ArgumentException(type.Name); } foreach (T item in Items) { if (item == null) { result.Add(item); } else { T clone = (T)((ICloneable)item).Clone(); result.Add(clone); } } } else { foreach (T item in Items) { result.Add(item); } } return(result); }
/// <inheritdoc cref="ICloneable.Clone" /> public object Clone() { CloneableCollection <T> result = new CloneableCollection <T>(); foreach (T item in this) { result.Add(item); } return(result); }