I have following event class. I have a question related to the Property method set {userAccount = value;} It will make a copy of the userAccount object (deep copy?) or it will make a copy of the userAccount object reference (shallow copy?) Do I need to make a method in UserAccountInfo class to do value copy?
class EvEndGetUserAccount
{
private UserAccountInfo userAccount;
/// <summary>
/// An event class for getting user account
/// </summary>
/// <param name="account"></param>
public EvEndGetUserAccount(UserAccountInfo account)
{
userAccount = account;
}
/// <summary>
/// Get/Set userAccount
/// </summary>
public UserAccountInfo UserAccount
{
get { return userAccount; }
set { userAccount = value; }
}
/// <summary>
/// returns the content of this EvEndGetUserAccount event.
/// </summary>
/// <returns>string represent of the EvEndGetUserAccount object</returns>
public override string ToString()
{
return userAccount.ToString();
}
}
It will make a shallow copy, in other words it will just copy the reference. If you want to make a deep copy (or clone), add the IClonable interface to your class. It will force you to add a new Clone method that implements the exact deep-copying logic