PageConfigurationUIButtonCopy_Click Method |
Namespace: SOWIWin.Helper
/// <summary> /// Button event: copies and inserts selected configuration /// </summary> /// <param name="sender">Button object</param> /// <param name="e"></param> protected override void ButtonCopy_Click(object sender, RoutedEventArgs e) { try { var lItem = this.DataGridConfiguration.SelectedItem; var lItemCopy = (DataItemClass)Copy(lItem); var lItemCopyXML = (SIC.Setting.ISettingXML)lItemCopy; lItemCopyXML.Name = Guid.NewGuid().ToString(); lItemCopy = (DataItemClass)lItemCopyXML; this.Configuration.Insert(lItemCopy); this.DataGridConfiguration.DataContext = this.Configuration.GetAll(); } catch (Exception ex) { SOWIWin.Helper.Message.Show(ex.Message.ToString()); } }
/// <summary> /// Copies a object /// </summary> /// <param name="pObject">Object to copy</param> /// <returns>Copied object</returns> private object Copy(object pObject) { Type pType = pObject.GetType(); PropertyInfo[] pProperties = pType.GetProperties(); Object lMember = pType.InvokeMember("", System.Reflection.BindingFlags.CreateInstance, null, pObject, null); foreach (PropertyInfo lProperty in pProperties) { if (lProperty.CanWrite) { try { lProperty.SetValue(lMember, lProperty.GetValue(pObject, null), null); } catch { // exception doesn't handling! } } } return lMember; }