public TemplateVariablesHelper(List <TemplateVariable> templateVariables) : this()
 {
     templateVariables.ForEach(x =>
     {
         TemplateVariables.Add(x.Name, x.Value);
     });
 }
Exemple #2
0
        /// <summary>
        /// Creates a template context instance.
        /// This will initialize the context properly and also create a concrete implementation of the template function.
        /// However, after creation, <see cref="Generate"/> has to be called to fill the freshly created function with life.
        /// </summary>
        /// <param name="templateContext">The context of the template element.</param>
        /// <param name="callerContext">The context of the caller of the template function.</param>
        /// <param name="template">The called template element.</param>
        public TemplateContext(Context templateContext, Context callerContext, IGenerationElementGenerator template)
            : base(templateContext.UpperContext, template.Generate(), new Dictionary <string, IGenerationElement>())
        {
            CallerContext = callerContext;
            _generator    = template;

            foreach (var i in template.TemplateList.Types)
            {
                TemplateVariables.Add(i.Name, null);
            }
        }
        private void ParseTemplateVariables(string templateText)
        {
            TemplateVariables.Clear();

            var matches = Regex.Matches(templateText, TemplateFileVarRegexPattern);

            foreach (Match match in matches)
            {
                string name = match.Value.Substring(1, match.Value.Length - 2);
                if (!TemplateVariables.Select(v => v.Name).Contains(name) && !ReservedTemplateVariables.Contains(name.ToUpper()))
                {
                    TemplateVariables.Add(new TemplateFileVariable {
                        Name = name
                    });
                }
            }
        }