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]); }
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(); }
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]; }
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; }
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); } }
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); } }
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(); }
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); }
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("./*")); } }
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; }
public LinqScalarModel(XmlNode xml, OperatorModelFactory models) : base(xml, models) { }
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(); }
public TestModel(XmlNode xml, OperatorModelFactory models) { this.Nested = models.CreateModel(xml.SelectSingleNode("./*")); }
public PlaceholderModel(XmlNode xml, OperatorModelFactory models) { this.Id = xml.GetMandatoryAttribute("of"); this.Operator = models.CreateModel(xml.GetMandatoryNode("./*")); }
public CodeBlockModel(XmlNode xml, OperatorModelFactory models) { this.Operators = xml.SelectNodes("./*").OfType <XmlNode>() .Select(models.CreateModel).ToList(); }
protected LogicalOperatorModel(XmlNode xml, OperatorModelFactory models) { this.Operands = xml.SelectNodes(@"./*").OfType <XmlNode>() .Select(models.CreateModel).ToList(); }
public ToStringModel(XmlNode xml, OperatorModelFactory models) { this.Format = xml.GetAttributeOrDefault("format") ?? string.Empty; this.Culture = xml.GetAttributeOrDefault("culture"); this.Argument = models.CreateModel(xml.SelectSingleNode(@"./*")); }
public LetModel(XmlNode xml, OperatorModel operand, OperatorModelFactory models) { this.Operand = operand; this.Variable = xml.GetMandatoryAttribute("as"); }
public NotModel(XmlNode xml, OperatorModelFactory models) { this.Operand = models.CreateModel(xml.GetMandatoryNode("./*")); }
public PropertyModel(XmlNode xml, OperatorModelFactory models) { this.Path = xml.GetMandatoryAttribute("valueOf"); }
public OrModel(XmlNode xml, OperatorModelFactory models) : base(xml, models) { }
public SwitchCaseModel(XmlNode xml, OperatorModelFactory models) { this.When = xml.GetMandatoryAttribute("when"); this.Operator = models.CreateModel(xml.SelectSingleNode("./*")); }
public MatchesOfModel(XmlNode xml, OperatorModelFactory models) { this.Pattern = xml.GetMandatoryAttribute("pattern"); this.Argument = models.CreateModel(xml.SelectSingleNode("./*")); }
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"); }