Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Verification on cloning
Message
De
10/12/2014 03:06:16
 
 
À
10/12/2014 00:25:24
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 8.1
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01612064
Message ID:
01612082
Vues:
45
totally beside the implemetation details another option would be to have an interface spelling out the differences of the action, for instance 2 methods named DeepCopy and ShallowCopy. Goes a bit against polymorphism as a concept, but does not require you to have a mental map on which objects .Clone has DeepCopy functionality added by clearly spelling out the action wanted. More clarity, less magic...

YMMV

thomas

>>That can be implemented in the Data class
>>In the Clone() method - first do the MemberWiseClone(), then copy the dataset
>>http://msdn.microsoft.com/en-us/library/system.icloneable(v=vs.110).aspx
>>
>>
>>Notes to Implementers
>>The ICloneable interface simply requires that your implementation of the Clone method return a copy of the current object instance. It does not specify whether the cloning operation performs a deep copy, a shallow copy, or something in between.
>>

>>
>>
>>	class Test_Clone
>>	{
>>		internal static void Go()
>>		{
>>
>>			Data d = new Data();
>>			// do some changes to d.oDataSet
>>
>>			Data cloned = d.Clone() as Data;
>>		}
>>	}
>>
>>	class Data : ICloneable
>>	{
>>		internal DataSet oDataSet = new DataSet();
>>		internal int Count = 4;
>>
>>		public object Clone()
>>		{
>>			Data cloned = (Data) MemberwiseClone();
>>			cloned.oDataSet = cloned.oDataSet.Copy();
>>
>>			return cloned;
>>		}
>>	}
>>
>
>That is a very interesting approach. Thanks
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform