public static string If(dynamic model, Action <string> then) { string value = DynamicHelper.Value(model); if (value != null) { try { then(value); } catch (FileLoadException e) { throw new LockedException(model.Path, e); } catch (ApiArgumentException) { throw; } catch (Exception e) { if (model is JValue) { throw new ApiArgumentException(model.Path, e); } throw; } } return(value); }
public static long?ToLong(dynamic value, int fromBase, long min = long.MinValue, long max = long.MaxValue) { string val = DynamicHelper.Value(value); if (val == null) { return(null); } try { var v = Convert.ToInt64(val, fromBase); Validator.WithinRange(min, max, v, value is JValue ? ((JValue)value).Path : string.Empty); return(v); } catch (FormatException e) { if (value is JValue) { throw new ApiArgumentException(value.Path, e); } throw; } }