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 Const(ConstModel constant, Type inferred = null) { this.create = () => "null".Equals(constant.Value) ? Expression.Constant(null, inferred ?? typeof(string)) : constant.Value.ToExpression(inferred ?? typeof(string)); }