Source/NFX/DataAccess/CRUD/Row.cs
/// <summary>
/// Tries to fill the row with data returning true if field count matched
/// </summary>
Tries to fill the row with data returning true if field count matched
Tries to fill the row with data returning true if field count matched
public static bool TryFillFromJSON(Row row, IJSONDataObject jsonData, SetFieldFunc setFieldFunc = null)
          {
            if (row==null || jsonData==null) return false;
            var allMatch = true;
            var map = jsonData as JSONDataMap;
            if (map!=null)
            {
              foreach(var kvp in map)
              {
                var fdef = row.Schema[kvp.Key];
                if (fdef==null)
                {
                  var ad = row as IAmorphousData;
                  if (ad!=null && ad.AmorphousDataEnabled)
                    ad.AmorphousData[kvp.Key] = kvp.Value;
                  allMatch = false;
                  continue;
                }
                if (setFieldFunc==null)
                  row.SetFieldValue(fdef, kvp.Value);
                else
                {
                  var ok = setFieldFunc(row, fdef, kvp.Value);
                  if (!ok) allMatch = false;
                }
              }
              if (map.Count!=row.Schema.FieldCount) allMatch = false;
            }
            else
            {
              var arr = jsonData as JSONDataArray;
              if (arr==null) return false;
              for(var i=0; i<row.Schema.FieldCount; i++)
              {
                 if (i==arr.Count) break;
                 var fdef = row.Schema[i];
                 if (setFieldFunc==null)
                   row.SetFieldValue(fdef, arr[i]);
                 else
                 {
                   var ok = setFieldFunc(row, fdef, arr[i]);
                   if (!ok) allMatch = false;
                 }
              }
              if (arr.Count!=row.Schema.FieldCount) allMatch = false;
            }
            return allMatch;
          }
public static bool TryFillFromJSON ( Row row , IJSONDataObject jsonData , SetFieldFunc setFieldFunc = null ) { if ( row == null || jsonData == null ) return false ; var allMatch = true ; var map = jsonData as JSONDataMap ; if ( map != null ) { foreach ( var kvp in map ) { var fdef = row . Schema [ kvp . Key ] ; if ( fdef == null ) { var ad = row as IAmorphousData ; if ( ad != null && ad . AmorphousDataEnabled ) ad . AmorphousData [ kvp . Key ] = kvp . Value ; allMatch = false ; continue ; } if ( setFieldFunc == null ) row . SetFieldValue ( fdef , kvp . Value ) ; else { var ok = setFieldFunc ( row , fdef , kvp . Value ) ; if ( ! ok ) allMatch = false ; } } if ( map . Count != row . Schema . FieldCount ) allMatch = false ; } else { var arr = jsonData as JSONDataArray ; if ( arr == null ) return false ; for ( var i = 0 ; i < row . Schema . FieldCount ; i ++ ) { if ( i == arr . Count ) break ; var fdef = row . Schema [ i ] ; if ( setFieldFunc == null ) row . SetFieldValue ( fdef , arr [ i ] ) ; else { var ok = setFieldFunc ( row , fdef , arr [ i ] ) ; if ( ! ok ) allMatch = false ; } } if ( arr . Count != row . Schema . FieldCount ) allMatch = false ; } return allMatch ; }
Tries to fill the row with data returning true if field count matched
Tries to fill the row with data returning true if field count matched
row
Row
jsonData
IJSONDataObject
setFieldFunc
SetFieldFunc