public T MapToModel() { foreach (var control in ControlsToMap) { IFormatProvider format = ControlsFormat.ContainsKey(control.Key) ? ControlsFormat[control.Key] is IFormatProvider ? (IFormatProvider)ControlsFormat[control.Key] : null : null; String formatString = ControlsFormat.ContainsKey(control.Key) ? ControlsFormat[control.Key] is String ? (String)ControlsFormat[control.Key] : null : null; if (control.Key is ListControl) { if (format != null) { _model.GetType().GetProperty(control.Value).SetValue(_model, Converter.Parse(((ListControl)control.Key).SelectedValue, _model.GetType().GetProperty(control.Value).PropertyType, format), null); } else if (formatString != null) { _model.GetType().GetProperty(control.Value).SetValue(_model, Converter.Parse(((ListControl)control.Key).SelectedValue, _model.GetType().GetProperty(control.Value).PropertyType, formatString), null); } else { _model.GetType().GetProperty(control.Value).SetValue(_model, Converter.Parse(((ListControl)control.Key).SelectedValue, _model.GetType().GetProperty(control.Value).PropertyType), null); } continue; } if (control.Key is ITextControl) { if (format != null) { _model.GetType().GetProperty(control.Value).SetValue(_model, Converter.Parse(((ITextControl)control.Key).Text, _model.GetType().GetProperty(control.Value).PropertyType, format), null); } else if (formatString != null) { _model.GetType().GetProperty(control.Value).SetValue(_model, Converter.Parse(((ITextControl)control.Key).Text, _model.GetType().GetProperty(control.Value).PropertyType, formatString), null); } else { _model.GetType().GetProperty(control.Value).SetValue(_model, Converter.Parse(((ITextControl)control.Key).Text, _model.GetType().GetProperty(control.Value).PropertyType), null); } continue; } } return(_model); }
public void MapToControls() { foreach (var control in ControlsToMap) { IFormatProvider format = ControlsFormat.ContainsKey(control.Key) ? ControlsFormat[control.Key] is IFormatProvider ? (IFormatProvider)ControlsFormat[control.Key] : null : null; string formatString = ControlsFormat.ContainsKey(control.Key) ? ControlsFormat[control.Key] is String ? (String)ControlsFormat[control.Key] : null : null; if (control.Key is ListControl) { if (format != null) { ((ListControl)control.Key).SelectedValue = Converter.ToString(_model.GetType().GetProperty(control.Value).GetValue(_model, null), format); } else if (formatString != null) { ((ListControl)control.Key).SelectedValue = Converter.ToString(_model.GetType().GetProperty(control.Value).GetValue(_model, null), formatString); } else { ((ListControl)control.Key).SelectedValue = Converter.ToString(_model.GetType().GetProperty(control.Value).GetValue(_model, null)); } continue; } if (control.Key is ITextControl) { if (format != null) { ((ITextControl)control.Key).Text = Converter.ToString(_model.GetType().GetProperty(control.Value).GetValue(_model, null), format); } else if (formatString != null) { ((ITextControl)control.Key).Text = Converter.ToString(_model.GetType().GetProperty(control.Value).GetValue(_model, null), formatString); } else { ((ITextControl)control.Key).Text = Converter.ToString(_model.GetType().GetProperty(control.Value).GetValue(_model, null)); } continue; } } }