Hi i am trying to clone a object which has a member list object
public class GrossTemplatesInfo
{
public List<GrossTemplates> grossTemplates { get; set; }
public object Clone()
{
GrossTemplatesInfo other = (GrossTemplatesInfo)this.MemberwiseClone();
other.grossTemplates = new List<GrossTemplates>(grossTemplates);
return other;
}
}
public class GrossTemplates : ICloneable
{
public string tempID { get; set; }
public string PreferenceName { get; set; }
public string PreferenceValue { get; set; }
public bool isDefault { get; set; }
object ICloneable.Clone()
{
return this.Clone();
}
public object Clone()
{
return this.MemberwiseClone();
}
}
and my method is something like this
public static GrossTemplatesInfo LoadInitialdata(string caseType)
{
GrossTemplatesInfo a = new GrossTemplatesInfo();
GrossTemplatesInfo b = a.Clone() as GrossTemplatesInfo;
}
I have done this and i am not getting the values in cloned object 'b' that are in original object 'a'. any help? i am kinda new to this cloning mechanism.