Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Verification on cloning
Message
De
09/12/2014 12:22:20
 
 
À
09/12/2014 11:56:58
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:
01612066
Vues:
81
This message has been marked as the solution to the initial question of the thread.
>I would like to verify something on cloning. I have a data provider class which includes this:
>
>
>Public Class Data
>    Implements ICloneable
>
>    Public Function Clone() As Object Implements System.ICloneable.Clone
>        Return MyBase.MemberwiseClone()
>    End Function
>
>
>Then, from a client class, I can do this:
>
>
>    Public oData As Data = New Data(oProcess)
>    Public oDataExcel As Data = New Data(oProcess)
>
>            ' Keep a reference to it as we will need to switch it back after the export
>            oDataExcel = oData.Clone
>
>
>This works. However, I just found out that this works only for the cloning of members and not the data itself. For example, in this case, I have a dataset attached to it such as oData.oDataSet. In that case, the data, if changed after the cloning has been done, will not be preserved.
>
>I believe something has to be changed at the Data class level in the Clone() method.

>Anyone would know what has to be done in order to assure to everything under the Data class would be cloned properly?

If I understand you correctly,
As per the doc, memberwiseClone only copies value types. As to objects (like dataset) it only copies the reference, meaning both references point to the same dataset

Maybe you want DataSet.Copy() http://msdn.microsoft.com/en-us/library/system.data.dataset.copy(v=vs.110).aspx
>
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform