I need to clone a list of object in Xamarin. Forms a project. The list is bounded to a View:
<StackLayout
BindableLayout.ItemsSource="{Binding list1}"
BindableLayout.ItemTemplateSelector="{Binding MyTemplateSelector}" />
I already saw many ways but no one works in my environment.
I have used this function to clone a list:
public static List<T> Clone<T>(this List<T> oldList)
{
var newList = new List<T>(oldList.Capacity);
newList.AddRange(oldList);
return newList;
}
Then I use it in this way
list2 = list1.Clone();
This works, if I add or remove some elements to list1
; in list2
the elements remains the same.
But if I modify the value of a element's property, the edited value is copied to list2
.
How can I solve this?
EDIT: This is a class that I need to copy
[VolosClass, Serializable, PropertyChanged.DoNotNotify]
public class WorkOrderChecklistDettaglio : BaseModel
{
public double? Progressivo_Vis { get; set; } // progr_vis
public double? Progressivo { get; set; } // progr
public double? Progressivo_Unico_Checklist { get; set; } // progr_unica_checklist
public string CodiceChecklist { get; set; } // codckl
public string GuidDettaglio { get; set; } // guid_dett
public string GuidDettaglioPadre { get; set; } // guid_dett_padre
public string Descrizione { get; set; } // descr
public string DescrizioneProdotto { get; set; } // descr_prodotto
/// <summary>
/// tabella standard CKT
/// C=campo F=flag N=nessuno T=tabella
/// codice
/// </summary>
public string TipoCampo { get; set; } // tipo_oper
public string TipoCampo_2 { get; set; } // tipo_oper2
/// <summary>
/// tabella standard SCH
/// tabella generica per checklist
///codice
/// </summary>
public string CodTab { get; set; } // cod_tab
public string CodTab_2 { get; set; } // cod_tab2
public string Flag { get; set; }
public string Flag_2 { get; set; }
public string Ris { get; set; }
public string Ris_2 { get; set; }
public string Valore { get; set; }
public string Valore_2 { get; set; }
public string Obbligatorio { get; set; } // ind_obb
public string Obbligatorio_2 { get; set; } // ind_obb2
public int? NumeroAllegati { get; set; } // contaAllegati
public int? NumeroNote { get; set; } // contaNote
#region Costruzione TreeView
public int Livello { get; set; } = -1;
public List<WorkOrderChecklistDettaglio> Children { get; set; }
public bool IsRequired { get; set; } = false;
#endregion
}