コード例 #1
0
        public BinaryComparerModel(XmlNode xml, OperatorModelFactory models)
        {
            var allowedOperations = typeof(BinaryComparerModel).GetProperty("Operation")
                                    .GetCustomAttributes <AllowedValueAttribute>()
                                    .Select(attribute => attribute.Value).OfType <ExpressionType>().ToList();

            try
            {
                this.Operation = xml.GetMandatoryAttribute <ExpressionType>("if");
            }
            catch (Exception e)
            {
                string message = "The value of 'operator' attribute is invalid.";
                message = message + " Allowed values are " + allowedOperations.Select(operation => operation.ToString()).Agglutinate(", ");
                throw new ExpressionConfigException(message, e);
            }

            if (allowedOperations.All(operation => operation != this.Operation))
            {
                string message = "The following operator is not supported: " + this.Operation;
                throw new ExpressionConfigException(message);
            }

            XmlNodeList operators = xml.SelectNodes(@"./*");

            if (operators == null || operators.Count != 2)
            {
                throw new ExpressionConfigException("The condition must have exactly two operands.");
            }

            this.Left  = models.CreateModel(operators[0]);
            this.Right = models.CreateModel(operators[1]);
        }
コード例 #2
0
ファイル: MethodCallModel.cs プロジェクト: lxdotnet/lxdn-core
        public MethodCallModel(XmlNode xml, OperatorModelFactory models)
        {
            this.Target = xml.GetMandatoryAttribute("for");
            this.Method = xml.GetMandatoryAttribute("method");

            this.Arguments = xml.SelectNodes("./*").OfType <XmlNode>()
                             .Select(models.CreateModel).ToList();
        }
コード例 #3
0
ファイル: LinqBaseModel.cs プロジェクト: lxdotnet/lxdn-core
        protected LinqBaseModel(XmlNode xml, OperatorModelFactory models)
        {
            this.Enumerable = xml.GetAttributeOrDefault("in") ?? xml.GetAttributeOrDefault("of");
            if (string.IsNullOrEmpty(this.Enumerable))
            {
                throw new XmlConfigException("The linq target collection must be referenced by 'in' of 'of' attribute.");
            }

            this.Verb = xml.Name.Split('.')[1];
        }
コード例 #4
0
ファイル: ConstModel.cs プロジェクト: lxdotnet/lxdn-core
        public ConstModel(XmlNode xml, OperatorModelFactory models)
        {
            XmlNode constant = xml.Attributes["value"];

            if (null == constant) // allow empty
            {
                throw new ExpressionConfigException("The value of a constant is absent.");
            }

            this.Value = constant.Value;
        }
コード例 #5
0
ファイル: IfModel.cs プロジェクト: lxdotnet/lxdn-core
        public IfModel(XmlNode xml, OperatorModelFactory models)
        {
            this.Condition = models.CreateModel(xml.GetMandatoryNode(@"./Condition/*"));
            this.Then      = models.CreateModel(xml.GetMandatoryNode(@"./Then/*"));

            XmlNode @else = xml.SelectSingleNode(@"./Else/*");

            if (@else != null)
            {
                this.Else = models.CreateModel(@else);
            }
        }
コード例 #6
0
        public SwitchModel(XmlNode xml, OperatorModelFactory models)
        {
            this.Key = xml.GetMandatoryAttribute("key");

            this.Cases = xml.SelectNodes("./SwitchCase").OfType <XmlNode>()
                         .Select(c => new SwitchCaseModel(c, models)).ToList();

            var @default = xml.SelectSingleNode("./Default/*");

            if (@default != null)
            {
                this.Default = models.CreateModel(@default);
            }
        }
コード例 #7
0
ファイル: ThrowModel.cs プロジェクト: lxdotnet/lxdn-core
        public ThrowModel(XmlNode xml, OperatorModelFactory models)
        {
            //var message = xml.GetAttributeOrDefault("message");

            //this.Message = !string.IsNullOrEmpty(message)
            //    ? new ConstModel(message) :
            //    models.CreateModel(xml.SelectSingleNode(@"./*"));

            this.Message = xml.SelectSingleNode(@"./Message/*").IfExists(m => models.CreateModel(m)) ??
                           models.CreateModel(xml.SelectSingleNode(@"./*"));

            this.Type = xml.GetAttributeOrDefault("type");

            this.Arguments = xml.SelectNodes(@"./Arguments/*").OfType <XmlNode>().Select(models.CreateModel).ToList();
        }
コード例 #8
0
        public MathModel(XmlNode xml, OperatorModelFactory models)
        {
            var nodes = new Pair <XmlNode>(xml.SelectNodes("./*").OfType <XmlNode>().ToList());

            this.Left  = models.CreateModel(nodes.Left);
            this.Right = models.CreateModel(nodes.Right);

            string operation = xml.Name.Split('.')[1];

            if (!Enum.IsDefined(typeof(ExpressionType), operation))
            {
                throw new ExpressionConfigException(operation + " is unknown binary expression type");
            }

            this.Operation = (ExpressionType)Enum.Parse(typeof(ExpressionType), operation);
        }
コード例 #9
0
ファイル: LinqLambdaModel.cs プロジェクト: lxdotnet/lxdn-core
        public LinqLambdaModel(XmlNode xml, OperatorModelFactory models)
            : base(xml, models)
        {
            var lambda = xml.SelectSingleNode("./Lambda");

            if (lambda != null)
            {
                this.Parameters = lambda.GetMandatoryAttribute("capture");//.SplitBy(' ', ',').ToList();

                if (!this.Parameters.Any())
                {
                    throw new ExpressionConfigException("Inner lambda contains no closure variables");
                }

                this.Body = models.CreateModel(lambda.SelectSingleNode("./*"));
            }
        }
コード例 #10
0
        public StringFormatModel(XmlNode xml, OperatorModelFactory models)
        {
            Func <string, string> squareTagsToHtml = s =>
                                                     Regex.Replace(s, @"\[(?'tag'.+?)\]", match =>
                                                                   string.Format("<{0}>", match.Groups["tag"].Value));

            var pattern = squareTagsToHtml(xml.GetMandatoryAttribute("pattern"));

            var constant = new ConstModel(pattern);

            this.Arguments = xml.SelectNodes("./*").OfType <XmlNode>().Select(models.CreateModel).ToList();

            if (constant.Value.MatchesOf(@"\{.+?\}").Count() != this.Arguments.Count())
            {
                throw new XmlConfigException("The count of arguments in the format string does not match the count of parameters");
            }

            this.Format = constant;
        }
コード例 #11
0
ファイル: LinqScalarModel.cs プロジェクト: lxdotnet/lxdn-core
 public LinqScalarModel(XmlNode xml, OperatorModelFactory models) : base(xml, models)
 {
 }
コード例 #12
0
 public StringFormatExModel(XmlNode xml, OperatorModel format, OperatorModelFactory models)
 {
     this.Format       = format;
     this.Placeholders = xml.SelectNodes("./Placeholder").OfType <XmlNode>()
                         .Select(a => new PlaceholderModel(a, models)).ToList();
 }
コード例 #13
0
ファイル: TestOperator.cs プロジェクト: lxdotnet/lxdn-core
 public TestModel(XmlNode xml, OperatorModelFactory models)
 {
     this.Nested = models.CreateModel(xml.SelectSingleNode("./*"));
 }
コード例 #14
0
 public PlaceholderModel(XmlNode xml, OperatorModelFactory models)
 {
     this.Id       = xml.GetMandatoryAttribute("of");
     this.Operator = models.CreateModel(xml.GetMandatoryNode("./*"));
 }
コード例 #15
0
ファイル: CodeBlockModel.cs プロジェクト: lxdotnet/lxdn-core
 public CodeBlockModel(XmlNode xml, OperatorModelFactory models)
 {
     this.Operators = xml.SelectNodes("./*").OfType <XmlNode>()
                      .Select(models.CreateModel).ToList();
 }
コード例 #16
0
 protected LogicalOperatorModel(XmlNode xml, OperatorModelFactory models)
 {
     this.Operands = xml.SelectNodes(@"./*").OfType <XmlNode>()
                     .Select(models.CreateModel).ToList();
 }
コード例 #17
0
ファイル: ToStringModel.cs プロジェクト: lxdotnet/lxdn-core
 public ToStringModel(XmlNode xml, OperatorModelFactory models)
 {
     this.Format   = xml.GetAttributeOrDefault("format") ?? string.Empty;
     this.Culture  = xml.GetAttributeOrDefault("culture");
     this.Argument = models.CreateModel(xml.SelectSingleNode(@"./*"));
 }
コード例 #18
0
 public LetModel(XmlNode xml, OperatorModel operand, OperatorModelFactory models)
 {
     this.Operand  = operand;
     this.Variable = xml.GetMandatoryAttribute("as");
 }
コード例 #19
0
 public NotModel(XmlNode xml, OperatorModelFactory models)
 {
     this.Operand = models.CreateModel(xml.GetMandatoryNode("./*"));
 }
コード例 #20
0
 public PropertyModel(XmlNode xml, OperatorModelFactory models)
 {
     this.Path = xml.GetMandatoryAttribute("valueOf");
 }
コード例 #21
0
 public OrModel(XmlNode xml, OperatorModelFactory models) : base(xml, models)
 {
 }
コード例 #22
0
ファイル: SwitchCaseModel.cs プロジェクト: lxdotnet/lxdn-core
 public SwitchCaseModel(XmlNode xml, OperatorModelFactory models)
 {
     this.When     = xml.GetMandatoryAttribute("when");
     this.Operator = models.CreateModel(xml.SelectSingleNode("./*"));
 }
コード例 #23
0
ファイル: MatchesOfModel.cs プロジェクト: lxdotnet/lxdn-core
 public MatchesOfModel(XmlNode xml, OperatorModelFactory models)
 {
     this.Pattern  = xml.GetMandatoryAttribute("pattern");
     this.Argument = models.CreateModel(xml.SelectSingleNode("./*"));
 }
コード例 #24
0
 public StringOccurenceModel(XmlNode xml, OperatorModelFactory models)
 {
     this.Source    = models.CreateModel(xml.GetMandatoryNode(@"./*"));
     this.Value     = new ConstModel(xml.GetMandatoryAttribute("of"));
     this.Occurence = xml.GetMandatoryAttribute <StringOccurenceKind>("predicate");
 }