public static int ToInt(this string text) { if (int.TryParse(text, out int num)) { return(num); } else { throw Fault.BadCast(text, num); } }
private int GetNodeID(Dictionary <string, object> dict) { if (Result == null) { throw Fault.NullRef <Dictionary <string, object> >(nameof(Result)); } object obj; if (!Result.TryGetValue("nid", out obj)) { throw Fault.NoMember("nid"); } if (obj == null) { throw Fault.NullRef <object>("nid"); } var json = obj.ToString(); if (json.IsBlank()) { throw Fault.BlankText("json nid"); } json = json.Replace("\"", ""); var numbr = json.Between("[{value:", "}]"); if (!numbr.IsNumeric()) { throw Fault.BadCast <int>(numbr); } return(numbr.ToInt()); }
public CollectorDTO GetCollector(SectionDTO sec) { if (_collectorBySecID.TryGetValue(sec.Id, out CollectorDTO cachd)) { return(cachd); } var val = Meta[string.Format(COLLECTOR_KEY, sec.Id)]; if (val.IsBlank()) { return(null); } if (!int.TryParse(val, out int id)) { throw Fault.BadCast(val, id); } cachd = _mkt.Collectors.Find(id, true); _collectorBySecID.Add(sec.Id, cachd); return(cachd); }