public DatabaseContractLoader <TContract> ForProperty <TProperty>(Expression <Func <TContract, TProperty> > property, string jsonKey, string associatedIdPropertyName, bool validateSchema = false) where TProperty : IContract { var token = ContractRaw.TryGetValue(jsonKey, out JToken member); if (token) { if (validateSchema) { var schema = GetPropertySchema(property); var valid = member.ToObject <JObject>().IsValid(schema); if (!valid) { return(this); } } var propertyContract = member.ToObject <TProperty>(); var id = SaveProperty(property, propertyContract).Result; typeof(TContract).GetProperty(associatedIdPropertyName).SetValue(Contract, id); } else { throw new Exception($"Unable to map JSON response to ${typeof(TProperty).Name}"); } return(this); }
public DatabaseContractLoader(string url) { var responseText = client.GetStringAsync(url).Result; ContractRaw = JObject.Parse(responseText); Contract = ContractRaw.ToObject <TContract>(); ResponseText = responseText; Client = new DatabaseClient(); }