Пример #1
0
        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);
        }
Пример #2
0
        public DatabaseContractLoader(string url)
        {
            var responseText = client.GetStringAsync(url).Result;

            ContractRaw  = JObject.Parse(responseText);
            Contract     = ContractRaw.ToObject <TContract>();
            ResponseText = responseText;
            Client       = new DatabaseClient();
        }