Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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;
         }
     }
 }
Ejemplo n.º 3
0
 public void RemoveFormatting(Control control)
 {
     ControlsFormat.Remove(control);
 }
Ejemplo n.º 4
0
 public void AddFormatting(Control control, object format)
 {
     ControlsFormat.Add(control, format);
 }