Exemplo n.º 1
0
 /// <summary>
 /// Sets the data object values from the given data contract object
 /// by copying the values of the data contract object fields to the
 /// data object properties or child objects with the same names.
 /// If there is no exact match between some data contract field names
 /// and the data object property names, this method can be overridden
 /// in the subclass to address each such case.
 /// </summary>
 /// <param name="dataContract">The data contract object to copy the values from.</param>
 /// <param name="options">Additional options for the operation.</param>
 public virtual void FromDataContract(object dataContract, object options)
 {
     if (dataContract == null)
     {
         return;
     }
     SetModified(false, false);
     foreach (PropertyInfo pi in dataContract.GetType().GetProperties())
     {
         object       val = pi.GetValue(dataContract, null);
         DataProperty dp  = this[pi.Name];
         DataObject   child;
         if (dp != null)
         {
             dp.Modified = null;
             dp.SetValue(val);
         }
         else if ((child = this.GetChildObject(pi.Name)) != null)
         {
             child.FromDataContract(val, options);
         }
         else if (val != null)
         {
             foreach (PropertyInfo cpi in pi.PropertyType.GetProperties())
             {
                 DataProperty cdp = this[pi.Name + "_" + cpi.Name];
                 if (cdp != null)
                 {
                     cdp.Modified = null;
                     cdp.SetValue(cpi.GetValue(val, null));
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Updates the property with the given value from the element.
 /// </summary>
 /// <param name="value">The value to set on the data property.</param>
 protected virtual void UpdateProperty(object value)
 {
     if (property != null && !PreventModelUpdate)
     {
         bool b = PreventElementUpdate;
         PreventElementUpdate = true;
         property.SetEditing(true, row);
         property.SetValue(value, row);
         PreventElementUpdate = b;
     }
 }