コード例 #1
0
 /// <summary>
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected ExpressionArgument(SerializationInfo info, StreamingContext context)
 {
     Name = info.GetString(nameof(Name));
     MorestachioExpression =
         info.GetValue(nameof(MorestachioExpression), typeof(IMorestachioExpression)) as IMorestachioExpression;
     Location = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
 }
コード例 #2
0
        /// <inheritdoc />
        public void ReadXml(XmlReader reader)
        {
            Location          = CharacterLocation.FromFormatString(reader.GetAttribute(nameof(Location)));
            EndsWithDelimiter = reader.GetAttribute(nameof(EndsWithDelimiter)) == bool.TrueString;
            var pathParts = new List <KeyValuePair <string, PathType> >();

            reader.ReadStartElement();            //Path

            if (reader.Name == "Path")
            {
                reader.ReadStartElement();                //Any SubPath

                while (reader.Name != "Path" && reader.NodeType != XmlNodeType.EndElement)
                {
                    var    partName  = reader.Name;
                    string partValue = null;
                    if (reader.IsEmptyElement)
                    {
                        reader.ReadStartElement();
                    }
                    else
                    {
                        partValue = reader.ReadElementContentAsString();
                    }
                    pathParts.Add(new KeyValuePair <string, PathType>(partValue, (PathType)Enum.Parse(typeof(PathType), partName)));
                }
                reader.ReadEndElement();                //</Path>
            }
            PathParts = new Traversable(pathParts);
            if (reader.Name == "Format" && reader.NodeType == XmlNodeType.Element)
            {
                FormatterName = reader.GetAttribute(nameof(FormatterName));
                if (reader.IsEmptyElement)
                {
                    reader.ReadStartElement();
                }
                else
                {
                    reader.ReadStartElement();                     //<Argument>
                    while (reader.Name == "Argument" && reader.NodeType != XmlNodeType.EndElement)
                    {
                        var formatSubTree = reader.ReadSubtree();
                        formatSubTree.Read();

                        var expressionArgument = new ExpressionArgument();
                        Formats.Add(expressionArgument);

                        expressionArgument.ReadXml(formatSubTree);

                        reader.Skip();
                        reader.ReadEndElement();
                    }
                    reader.ReadEndElement();                    //</Format>
                }
            }
            reader.ReadEndElement();
        }
コード例 #3
0
 /// <summary>
 ///		Serialization constructor
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected MorestachioExpression(SerializationInfo info, StreamingContext context)
 {
     PathParts = new Traversable(info.GetValue(nameof(PathParts), typeof(KeyValuePair <string, PathType>[])) as KeyValuePair <string, PathType>[]);
     Formats   = info.GetValue(nameof(Formats), typeof(IList <ExpressionArgument>))
                 as IList <ExpressionArgument>;
     FormatterName     = info.GetString(nameof(FormatterName));
     Location          = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
     EndsWithDelimiter = info.GetBoolean(nameof(EndsWithDelimiter));
 }
コード例 #4
0
 protected MorestachioExpression(SerializationInfo info, StreamingContext context)
 {
     PathParts = info.GetValue(nameof(PathParts), typeof(IList <KeyValuePair <string, PathType> >))
                 as IList <KeyValuePair <string, PathType> >;
     Formats = info.GetValue(nameof(Formats), typeof(IList <ExpressionArgument>))
               as IList <ExpressionArgument>;
     FormatterName = info.GetString(nameof(FormatterName));
     Location      = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
 }
コード例 #5
0
        /// <inheritdoc />
        public void ReadXml(XmlReader reader)
        {
            Location = CharacterLocation.FromFormatString(reader.GetAttribute(nameof(Location)));
            Name     = reader.GetAttribute(nameof(Name));
            reader.ReadStartElement();

            var expSubtree = reader.ReadSubtree();

            expSubtree.Read();
            MorestachioExpression = expSubtree.ParseExpressionFromKind();
        }
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected MorestachioOperatorExpression(SerializationInfo info, StreamingContext context)
        {
            Location = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
            var opText = info.GetString(nameof(Operator));

            Operator       = MorestachioOperator.Yield().First(f => f.OperatorText.Equals(opText));
            LeftExpression =
                info.GetValue(nameof(LeftExpression), typeof(IMorestachioExpression)) as IMorestachioExpression;
            RightExpression =
                info.GetValue(nameof(RightExpression), typeof(IMorestachioExpression)) as IMorestachioExpression;
        }
コード例 #7
0
        protected DocumentItemBase(SerializationInfo info, StreamingContext c)
        {
            var expStartLocation = info.GetString(nameof(ExpressionStart));

            if (!string.IsNullOrWhiteSpace(expStartLocation))
            {
                ExpressionStart = CharacterLocation.FromFormatString(expStartLocation);
            }

            TagCreationOptions =
                info.GetValue(nameof(TagCreationOptions), typeof(IEnumerable <ITokenOption>)) as IEnumerable <ITokenOption>;
        }
コード例 #8
0
        protected DocumentItemBase(SerializationInfo info, StreamingContext c)
        {
            var documentItemBases = info.GetValue(nameof(Children), typeof(IDocumentItem[])) as IDocumentItem[];

            Children = new List <IDocumentItem>(documentItemBases ?? throw new InvalidOperationException());
            var expStartLocation = info.GetString(nameof(ExpressionStart));

            if (!string.IsNullOrWhiteSpace(expStartLocation))
            {
                ExpressionStart = CharacterLocation.FromFormatString(expStartLocation);
            }
        }
コード例 #9
0
        /// <inheritdoc />
        public void ReadXml(XmlReader reader)
        {
            var opText = reader.GetAttribute(nameof(Operator));

            Operator = MorestachioOperator.Yield().First(f => f.OperatorText.Equals(opText));
            Location = CharacterLocation.FromFormatString(reader.GetAttribute(nameof(Location)));
            reader.ReadStartElement();
            var leftSubTree = reader.ReadSubtree();

            LeftExpression = leftSubTree.ParseExpressionFromKind();
            if (reader.Name == nameof(RightExpression))
            {
                var rightSubtree = reader.ReadSubtree();
                RightExpression = rightSubtree.ParseExpressionFromKind();
            }
        }
コード例 #10
0
        public void TemplateInvalidContentBetweenIfAndElse()
        {
            var template =
                @"{{^IF data}}{{data}}{{/IF}}{{data}}{{#else}}{{root}}{{/else}}";

            var parsedTemplate =
                Parser.ParseWithOptions(new ParserOptions(template, null, ParserFixture.DefaultEncoding));

            var model = new Dictionary <string, object>()
            {
                { "data", "false" },
                { "root", "true" }
            };

            Assert.That(parsedTemplate.Errors
                        .OfType <MorestachioSyntaxError>()
                        .FirstOrDefault(e => e.Location.Equals(CharacterLocation.FromFormatString("1:36"))), Is.Not.Null);
        }
コード例 #11
0
        public async Task TemplateInvalidContentBetweenIfAndElse()
        {
            var template =
                @"{{^IF data}}{{data}}{{/IF}}{{data}}{{#else}}{{root}}{{/else}}";

            var data = new Dictionary <string, object>()
            {
                { "data", "false" },
                { "root", "true" }
            };

            var result = await ParserFixture.CreateAndParseWithOptions(template, data, _options, null, info =>
            {
                Assert.That(info.Errors
                            .OfType <MorestachioSyntaxError>()
                            .FirstOrDefault(e => e.Location.Equals(CharacterLocation.FromFormatString("1:38,38"))), Is.Not.Null);
            });
        }
コード例 #12
0
        /// <inheritdoc />
        public void ReadXml(XmlReader reader)
        {
            Location = CharacterLocation.FromFormatString(reader.GetAttribute(nameof(Location)));
            if (reader.IsEmptyElement)
            {
                return;
            }
            reader.ReadStartElement();
            while (reader.Name == nameof(ExpressionStringConstPart) && reader.NodeType != XmlNodeType.EndElement)
            {
                var strLocation      = CharacterLocation.FromFormatString(reader.GetAttribute(nameof(Location)));
                var constStrPartText = reader.ReadElementContentAsString();
                Delimiter = constStrPartText[0];
                var strPartText = constStrPartText.Substring(1, constStrPartText.Length - 2);

                StringParts.Add(new ExpressionStringConstPart(strPartText, strLocation));
                reader.ReadEndElement();
            }
        }
コード例 #13
0
        /// <inheritdoc />
        public void ReadXml(XmlReader reader)
        {
            Location = CharacterLocation.FromFormatString(reader.GetAttribute(nameof(Location)));
            if (reader.IsEmptyElement)
            {
                return;
            }
            reader.ReadStartElement();
            var expression = new List <IMorestachioExpression>();

            while (reader.NodeType == XmlNodeType.Element)
            {
                var childTree = reader.ReadSubtree();
                childTree.Read();
                expression.Add(childTree.ParseExpressionFromKind());
                reader.Skip();
            }

            Expressions = expression.ToArray();
        }
コード例 #14
0
        /// <inheritdoc />
        void IDocumentItem.DeSerializeXmlCore(XmlReader reader)
        {
            AssertElement(reader, GetSerializedMarkerName(GetType()));

            var charLoc = reader.GetAttribute(nameof(ExpressionStart));

            if (charLoc != null)
            {
                ExpressionStart = CharacterLocation.FromFormatString(charLoc);
            }

            if (!reader.IsEmptyElement)
            {
                var readSubtree = reader.ReadSubtree();
                readSubtree.Read();
                DeSerializeXml(readSubtree);

                if (reader.Name == "Children" || reader.ReadToFollowing(nameof(Children)))
                {
                    reader.ReadStartElement();                     //nameof(Children)
                    while (!reader.Name.Equals(nameof(Children)) && reader.NodeType != XmlNodeType.EndElement)
                    {
                        var child = DocumentExtenstions.CreateDocumentItemInstance(reader.Name);

                        var childTree = reader.ReadSubtree();
                        childTree.Read();
                        child.DeSerializeXmlCore(childTree);
                        reader.Skip();
                        Children.Add(child);
                    }

                    reader.ReadEndElement();                     //nameof(Children)
                }

                if (reader.NodeType == XmlNodeType.EndElement && reader.Name.Equals(GetSerializedMarkerName(GetType())))
                {
                    //there are no children and we have reached the end of the document
                    reader.ReadEndElement();                     //GetType().Name
                }
            }
        }
コード例 #15
0
        /// <inheritdoc />
        void IDocumentItem.DeSerializeXmlCore(XmlReader reader)
        {
            AssertElement(reader, GetSerializedMarkerName(GetType()));

            var charLoc = reader.GetAttribute(nameof(ExpressionStart));

            if (charLoc != null)
            {
                ExpressionStart = CharacterLocation.FromFormatString(charLoc);
            }
            if (!reader.IsEmptyElement)
            {
                var readSubtree = reader.ReadSubtree();
                readSubtree.Read();
                DeSerializeXml(readSubtree);
                TagCreationOptions = reader.ReadOptions(nameof(TagCreationOptions));

                if (reader.NodeType == XmlNodeType.EndElement && reader.Name.Equals(GetSerializedMarkerName(GetType())))
                {
                    //there are no children and we have reached the end of the document
                    reader.ReadEndElement();                     //GetType().Name
                }
            }
        }
コード例 #16
0
        /// <inheritdoc />
        public void ReadXml(XmlReader reader)
        {
            Location      = CharacterLocation.FromFormatString(reader.GetAttribute(nameof(Location)));
            FormatterName = reader.GetAttribute(nameof(FormatterName));
            var pathParts = reader.GetAttribute(nameof(PathParts));

            if (pathParts != null)
            {
                PathParts = pathParts.Split(',').Select(f =>
                {
                    var parts = f.Trim('{', '}').Split(';');
                    return(new KeyValuePair <string, PathType>(parts.ElementAtOrDefault(1),
                                                               (PathType)Enum.Parse(typeof(PathType), parts[0])));
                }).ToList();
            }

            if (reader.IsEmptyElement)
            {
                return;
            }

            reader.ReadStartElement();
            while (reader.Name == "Format" && reader.NodeType != XmlNodeType.EndElement)
            {
                var formatSubTree = reader.ReadSubtree();
                formatSubTree.Read();

                var expressionArgument = new ExpressionArgument();
                Formats.Add(expressionArgument);

                expressionArgument.ReadXml(formatSubTree);

                reader.Skip();
                reader.ReadEndElement();
            }
        }
コード例 #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected MorestachioExpressionListBase(SerializationInfo info, StreamingContext context)
 {
     Location    = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
     Expressions = (IMorestachioExpression[])info.GetValue(nameof(Expressions), typeof(IMorestachioExpression[]));
 }
コード例 #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="info"></param>
 /// <param name="context"></param>
 protected MorestachioExpressionString(SerializationInfo info, StreamingContext context)
 {
     StringParts = (IList <ExpressionStringConstPart>)info.GetValue(nameof(StringParts), typeof(IList <ExpressionStringConstPart>));
     Location    = CharacterLocation.FromFormatString(info.GetString(nameof(Location)));
     Delimiter   = info.GetChar(nameof(Delimiter));
 }