AmazedSaint.Elastic.Templating.DynamicTemplateHost.Preprocess C# (CSharp) Метод

Preprocess() публичный Метод

Enhanced reg-ex based pre processing
public Preprocess ( string input ) : string
input string
Результат string
        public string Preprocess(string input)
        {
            Regex expressionInCode = new Regex(@"(\#\(.*?\s*?\))", RegexOptions.None);
            Regex expressionInTemp = new Regex(@"(\$\(.*?\s*?\))", RegexOptions.None);
            Regex expressionLoopStart = new Regex(@"\${1}[a-zA-Z0-9_ ]*\?\s*?\(.*?\)", RegexOptions.None);

            var matches = expressionInCode.Matches(input, 0);

            string data=input;

            //Process the matches
            foreach (var match in matches)
            {
                string formatted = match.ToString().Trim().Remove(0, 2);
                formatted = formatted.Remove(formatted.Length - 1);
                data = data.Replace(match.ToString(), "#><#=" + formatted + "#><#");
            }

            matches = expressionInTemp.Matches(data, 0);

            //Process the matches
            foreach (var match in matches)
            {
                string formatted = match.ToString().Trim().Remove(0, 2);
                formatted = formatted.Remove(formatted.Length - 1);
                data = data.Replace(match.ToString(), "<#=" + formatted + "#>");
            }

            matches = expressionLoopStart.Matches(data, 0);

            //Process the matches
            foreach (var match in matches)
            {
                string formatted = match.ToString().Trim().Remove(0, 1);
                formatted = formatted.Trim();
                string op = formatted.Remove(formatted.IndexOf("?")).Trim();
                string expression = formatted.Substring(formatted.IndexOf("?")+1).Trim();

                data = data.Replace(match.ToString(),"<# foreach(var " + op + " in " + expression + ") {#>");

                data = data.Replace("$" + op + " end" , "<# } #>");
            }

            return data;
        }