Ejemplo n.º 1
0
        /// <summary>
        /// Used for deserialization since the deserializer already created the <see cref="Template"/> object for us
        /// Assumes a new empty <see cref="Template"/> object
        /// </summary>
        private static void parseWithExistingTemplate(Template i_Template, string i_Input)
        {
            int currentInputIndex = 0;

            foreach (Match match in sr_DynamicSectionRegex.Matches(i_Input))
            {
                if (match.Index > currentInputIndex)
                {
                    i_Template.r_TextNodes.Add(new StaticTextNode(i_Input.Substring(currentInputIndex, match.Index - currentInputIndex)));
                }

                DynamicTextNode dynamicTextNode = new DynamicTextNode(match.Groups["name"].Value);
                if (!i_Template.r_DynamicTextNodes.ContainsKey(dynamicTextNode.Name))
                {
                    i_Template.r_DynamicTextNodes.Add(dynamicTextNode.Name, dynamicTextNode);
                }
                else
                {
                    dynamicTextNode = i_Template.r_DynamicTextNodes[dynamicTextNode.Name];
                }

                i_Template.r_TextNodes.Add(dynamicTextNode);
                currentInputIndex = match.Index + match.Length;
            }

            if (i_Input.Length > currentInputIndex)
            {
                i_Template.r_TextNodes.Add(new StaticTextNode(i_Input.Substring(currentInputIndex, i_Input.Length - currentInputIndex)));
            }
        }
Ejemplo n.º 2
0
        public override string ToString()
        {
            StringBuilder builder = new StringBuilder();

            foreach (ITextNode textNode in r_TextNodes)
            {
                DynamicTextNode node = textNode as DynamicTextNode;
                if (node != null)
                {
                    builder.Append(string.Format("{{{{{0}}}}}", node.Name));
                }
                else
                {
                    builder.Append(textNode.Text);
                }
            }

            return(builder.ToString());
        }
        /// <summary>
        /// Used for deserialization since the deserializer already created the <see cref="Template"/> object for us
        /// Assumes a new empty <see cref="Template"/> object
        /// </summary>
        private static void parseWithExistingTemplate(Template i_Template, string i_Input)
        {
            int currentInputIndex = 0;
            foreach (Match match in sr_DynamicSectionRegex.Matches(i_Input))
            {
                if (match.Index > currentInputIndex)
                {
                    i_Template.r_TextNodes.Add(new StaticTextNode(i_Input.Substring(currentInputIndex, match.Index - currentInputIndex)));
                }

                DynamicTextNode dynamicTextNode = new DynamicTextNode(match.Groups["name"].Value);
                if (!i_Template.r_DynamicTextNodes.ContainsKey(dynamicTextNode.Name))
                {
                    i_Template.r_DynamicTextNodes.Add(dynamicTextNode.Name, dynamicTextNode);
                }
                else
                {
                    dynamicTextNode = i_Template.r_DynamicTextNodes[dynamicTextNode.Name];
                }

                i_Template.r_TextNodes.Add(dynamicTextNode);
                currentInputIndex = match.Index + match.Length;
            }

            if (i_Input.Length > currentInputIndex)
            {
                i_Template.r_TextNodes.Add(new StaticTextNode(i_Input.Substring(currentInputIndex, i_Input.Length - currentInputIndex)));
            }
        }