Esempio n. 1
0
        /// <summary>
        /// Asynchronously 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 async Task UpdatePropertyAsync(object value)
        {
            if (property != null && !PreventModelUpdate)
            {
                bool b = PreventElementUpdate;
                PreventElementUpdate = true;
                property.SetEditing(true, row);
                await property.SetValueAsync(value, row);

                PreventElementUpdate = b;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Sets the values of the given data row or, if the row is null,
 /// the data object 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>
 /// <param name="row">The row to set the values for.
 /// <param name="token">Cancellation token.</param>
 /// Null to set values of the current data object.</param>
 protected async Task FromDataContractAsync(object dataContract, object options, DataRow row,
                                            CancellationToken token = default)
 {
     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;
             await dp.SetValueAsync(val, row, token);
         }
         else if ((child = GetChildObject(pi.Name)) != null)
         {
             await child.FromDataContractAsync(val, options, token);
         }
         else if (val != null)
         {
             foreach (PropertyInfo cpi in pi.PropertyType.GetProperties())
             {
                 DataProperty cdp = this[pi.Name + "_" + cpi.Name];
                 if (cdp != null)
                 {
                     cdp.Modified = null;
                     await cdp.SetValueAsync(cpi.GetValue(val, null), row, token);
                 }
             }
         }
     }
 }