public override void MapFromBase(BaseRule baseRule) { if (baseRule.RuleType != RuleType) { throw new Exception("Attempted instantiation of invalid rule type."); } ComparisonOperator = baseRule.ComparisonOperator; ComparisonType = baseRule.ComparisonType; CompareRuleObject = baseRule.CompareRuleObject; CompareSourceObject = baseRule.CompareSourceObject; ExpectedResult = baseRule.ExpectedResult; RuleType = baseRule.RuleType; }
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); }
public virtual void MapFromBase(BaseRule baseRule) { }