Example #1
0
        public override Rule ToRule(EventSlot slot)
        {
            var param = RuleParameterProviders.Providers.GetParameter(slot.EventType, Parameter);
            var rule = new SwitchCaseRule(param);

            foreach (var caze in Cases)
            {
                var value = Convert.ChangeType(caze.Value, param.ValueType);
                rule.Cases.Add(value, caze.Rules.Select(r => r.ToRule(slot)).ToList());
            }

            foreach (var defaultRule in Default)
            {
                rule.Default.Add(defaultRule.ToRule(slot));
            }

            return rule;
        }
Example #2
0
        public static SwitchCaseRuleModel FromRule(SwitchCaseRule rule)
        {
            var model = new SwitchCaseRuleModel
            {
                Parameter = rule.Parameter.Name
            };

            foreach (var caze in rule.Cases)
            {
                model.Cases.Add(new CaseModel
                {
                    Value = caze.Key.ToString(),
                    Rules = caze.Value.Select(r => RuleModelBase.FromRule(r)).ToList()
                });
            }

            foreach (var defaultRule in rule.Default)
            {
                model.Default.Add(RuleModelBase.FromRule(defaultRule));
            }

            return model;
        }