internal void CopyValues(ViewModelWindowMain vmMain) { List <string> errorProps = new List <string>(); string propertyName = null; object copyValue = null; foreach (PropertyInfo pi in this.GetType().GetProperties().Where(p => p.Name.StartsWith("Copy"))) { try { propertyName = pi.Name.Remove(0, 4); PropertyInfo copyPI = typeof(WindowMainCopySwitches).GetProperty(propertyName); PropertyInfo valuePI = vmMain.GetType().GetProperty(propertyName); if ((copyPI != null) && (valuePI != null) && (copyPI.PropertyType == valuePI.PropertyType)) { if ((bool)pi.GetValue(this, null)) { copyValue = valuePI.GetValue(vmMain, null); } else { copyValue = GetDefault(copyPI.PropertyType); } copyPI.SetValue(this, copyValue, null); } else { errorProps.Add(propertyName); } } catch { errorProps.Add(propertyName); } } if (errorProps.Count > 0) { MessageBox.Show(String.Format("Unable to copy {0}{1}.", errorProps.Count > 1 ? String.Format("the following {0} fields: \n\n", errorProps.Count) : "field ", String.Join(", ", errorProps.ToArray())), "HLU: Copy Error", MessageBoxButton.OK, MessageBoxImage.Error); } vmMain.OnPropertyChanged("CanPaste"); }
internal void PasteValues(ViewModelWindowMain vmMain) { List <string> errorProps = new List <string>(); string propertyName = null; foreach (PropertyInfo pi in this.GetType().GetProperties().Where(p => p.Name.StartsWith("Copy"))) { try { propertyName = pi.Name.Remove(0, 4); PropertyInfo copyPI = this.GetType().GetProperty(propertyName); PropertyInfo valuePI = vmMain.GetType().GetProperty(propertyName); if ((copyPI != null) && (valuePI != null) && (copyPI.PropertyType == valuePI.PropertyType)) { if ((bool)pi.GetValue(this, null)) { vmMain.Pasting = true; valuePI.SetValue(vmMain, copyPI.GetValue(this, null), null); vmMain.Pasting = false; } } else { errorProps.Add(propertyName); } } catch { errorProps.Add(propertyName); } finally { vmMain.Pasting = false; } } if (errorProps.Count > 0) { MessageBox.Show(String.Format("Unable to paste {0}{1}", errorProps.Count > 1 ? String.Format("the following {0} fields: \n\n", errorProps.Count) : "field ", String.Join(", ", errorProps.ToArray())), "HLU: Paste Error", MessageBoxButton.OK, MessageBoxImage.Error); } vmMain.RefreshAll(); }
internal void PasteValues(ViewModelWindowMain vmMain) { List<string> errorProps = new List<string>(); string propertyName = null; foreach (PropertyInfo pi in this.GetType().GetProperties().Where(p => p.Name.StartsWith("Copy"))) { try { propertyName = pi.Name.Remove(0, 4); PropertyInfo copyPI = this.GetType().GetProperty(propertyName); PropertyInfo valuePI = vmMain.GetType().GetProperty(propertyName); if ((copyPI != null) && (valuePI != null) && (copyPI.PropertyType == valuePI.PropertyType)) { if ((bool)pi.GetValue(this, null)) { vmMain.Pasting = true; valuePI.SetValue(vmMain, copyPI.GetValue(this, null), null); vmMain.Pasting = false; } } else { errorProps.Add(propertyName); } } catch { errorProps.Add(propertyName); } finally { vmMain.Pasting = false; } } if (errorProps.Count > 0) MessageBox.Show(String.Format("Unable to paste {0}{1}", errorProps.Count > 1 ? String.Format("the following {0} fields: \n\n", errorProps.Count) : "field ", String.Join(", ", errorProps.ToArray())), "HLU: Paste Error", MessageBoxButton.OK, MessageBoxImage.Error); vmMain.RefreshAll(); }
internal void CopyValues(ViewModelWindowMain vmMain) { List<string> errorProps = new List<string>(); string propertyName = null; object copyValue = null; foreach (PropertyInfo pi in this.GetType().GetProperties().Where(p => p.Name.StartsWith("Copy"))) { try { propertyName = pi.Name.Remove(0, 4); PropertyInfo copyPI = typeof(WindowMainCopySwitches).GetProperty(propertyName); PropertyInfo valuePI = vmMain.GetType().GetProperty(propertyName); if ((copyPI != null) && (valuePI != null) && (copyPI.PropertyType == valuePI.PropertyType)) { if ((bool)pi.GetValue(this, null)) copyValue = valuePI.GetValue(vmMain, null); else copyValue = GetDefault(copyPI.PropertyType); copyPI.SetValue(this, copyValue, null); } else { errorProps.Add(propertyName); } } catch { errorProps.Add(propertyName); } } if (errorProps.Count > 0) MessageBox.Show(String.Format("Unable to copy {0}{1}.", errorProps.Count > 1 ? String.Format("the following {0} fields: \n\n", errorProps.Count) : "field ", String.Join(", ", errorProps.ToArray())), "HLU: Copy Error", MessageBoxButton.OK, MessageBoxImage.Error); vmMain.OnPropertyChanged("CanPaste"); }