Пример #1
0
        public void Configure(IDictionary <string, object> src)
        {
            var jObject = JObject.FromObject(CompareRuleObject);

            //foreach (var property in jObject) Debug.WriteLine(property.Key + " - " + property.Value);

            var propertyName = jObject.Properties().First().Value.ToString();

            var sourceValue = PropertyUtils.GetPropertyValueByName(src, propertyName);

            CompareSourceObject = sourceValue;
        }
Пример #2
0
        public static List <RuleSet> ParseRuleSets(ref string json)
        {
            //dynamic d = JsonConvert.DeserializeObject<dynamic>(json);
            //string v = d.ToString();

            JObject parsed = JObject.Parse(json);
            JArray  array  = (JArray)parsed["RuleList"];

            List <RuleSet> ruleSetsDeserialized = JsonConvert.DeserializeObject <List <RuleSet> >(array.ToString());



            List <RuleSet> activeRuleSets = new List <RuleSet>();

            foreach (RuleSet ruleSet in ruleSetsDeserialized)
            {
                RuleSet         localRuleSet    = new RuleSet();
                List <BaseRule> activeBaseRules = new List <BaseRule>();
                foreach (BaseRule baseRule in ruleSet.RuleSets)
                {
                    string concreteType =
                        PropertyUtils.GetPropertyValueByName((object)baseRule, "RuleType").ToString();
                    IQueryable <Type> types = PropertyUtils.GetTypeByName(concreteType).AsQueryable <Type>();
                    Type     type           = types.FirstOrDefault(x => x.Name.ToString() == concreteType.ToString());
                    BaseRule concreteObj    = null;
                    try
                    {
                        concreteObj =
                            (BaseRule)Activator.CreateInstance(type ?? throw new InvalidOperationException());
                    }
                    catch (InvalidOperationException)
                    {
                        if (concreteType.ToLower() == "commentrule" || concreteType.ToLower() == "comment")
                        {
                            continue;
                        }
                        else
                        {
                            throw;
                        }
                    };
                    concreteObj?.MapFromBase(baseRule);
                    activeBaseRules.Add(concreteObj);
                }

                localRuleSet.RuleSets.AddRange(activeBaseRules);
                activeRuleSets.Add(localRuleSet);
            }

            return(activeRuleSets);
        }