/// <summary> /// Checks whether a clone is successful and returns the cloned object. /// </summary> /// <param name="the_cloneable">the object to clone.</param> /// <returns>the new cloned object.</returns> public static Cloneable cloneCheck(Cloneable the_cloneable) { Cloneable clone = (Cloneable)the_cloneable.clone(); //this check removes the chance of a programmer building a cloneable that //returns a reference to itself //this check ensures that after object.clone() is called, only a disconnected //object is returned if (the_cloneable == clone) { throw new ArgumentException("Clone method returns reference to the same object."); } return(clone); }
static void sheep() { Cloneable sheep = new Sheep(); Console.Write("\nCounting Sheep...\n\n"); CountUtil.count(sheep, 2); Console.Write("\n"); Cloneable sheepClone = sheep.cloneAnimal(sheep); CountUtil.count(sheepClone, 3); Console.Write("\n"); sheep.resetCount(); CountUtil.count(sheep, 1); }
static void Main(string[] args) { Countable objAlligator = new Alligator(); Console.WriteLine("Counting Alligator..."); CountUtil.count(objAlligator, 4); Console.WriteLine("\n"); Cloneable objSheep = new Sheep(); Console.WriteLine("Counting Sheep..."); CountUtil.count(objSheep, 3); Console.WriteLine("\n"); Cloneable sheepDuplicate = objSheep.cloneAnimal(objSheep); CountUtil.count(sheepDuplicate, 3); Console.WriteLine("\n"); objSheep.resetCount(); CountUtil.count(objSheep, 1); }
protected override void CloneOverride(Cloneable source) { // Copy all properties from source to 'this' description. }
protected override void CloneCore(Cloneable source) { }
protected override void CloneOverride(Cloneable source) { }
protected override void CloneOverride(Cloneable source) { // Copy all properties from source to 'this' description is applicable. }
protected override void CloneCore(Cloneable source) { var delegateGroupFilter = source as DelegateGroupFilter; this.FilterImpl = delegateGroupFilter.FilterImpl; }
/// <summary> /// Makes the instance a clone (deep copy) of the specified <see cref="Telerik.Data.Core.Cloneable"/>. /// </summary> /// <param name="source">The object to clone.</param> /// <remarks>Notes to Inheritors /// If you derive from <see cref="Telerik.Data.Core.Cloneable"/>, you need to override this method to copy all properties. /// It is essential that all implementations call the base implementation of this method (if you don't call base you should manually copy all needed properties including base properties). /// </remarks> protected abstract void CloneOverride(Cloneable source);
protected override void CloneOverride(Cloneable source) { throw new NotImplementedException(); }
Cloneable Cloneable.cloneAnimal(Cloneable animal) { animal = new Sheep(); animal.setCloneName("Dolly"); return(animal); }