Example #1
0
        /// <summary>
        /// Parse template before rendering.
        /// </summary>
        /// <remarks>
        /// Once parsed, you can render as much times as you want.
        /// </remarks>
        /// <exception cref="TemplateParsingException">
        /// If an error ocurrs during parsing such as wrong
        /// syntax used.
        /// </exception>
        /// <exception cref="TemplateCompilationException">
        /// If a bad dynamic language syntax is found such as
        /// a bad C# code syntax.
        /// </exception>
        public void Parse()
        {
            this.defaultInstance = new AtTemplateInstance(this);

            if (!string.IsNullOrEmpty(this.parser.TemplateFile))
            {
                using (StreamReader reader = new StreamReader(this.parser.TemplateFile, this.encoding))
                {
                    int c;
                    while ((c = reader.Read()) >= 0)
                    {
                        if ((char)c == '\n')
                        {
                            this.parser.LineEnding = "\n";
                            break;
                        }
                        else if ((char)c == '\r')
                        {
                            if ((c = reader.Read()) >= 0 && (char)c == '\n')
                            {
                                this.parser.LineEnding = "\r\n";
                            }
                            else
                            {
                                this.parser.LineEnding = "\r";
                            }
                            break;
                        }
                    }
                }

                this.parser.Reader = new StreamReader(this.parser.TemplateFile, this.encoding);
            }

            try
            {
                ParseTemplate();
                Compile();
                LoadAssembly();
            }
            finally
            {
                this.parser.Reader.Close();
            }
        }
Example #2
0
        /// <summary>
        /// Parse template before rendering.
        /// </summary>
        /// <remarks>
        /// Once parsed, you can render as much times as you want.
        /// </remarks>
        /// <exception cref="TemplateParsingException">
        /// If an error ocurrs during parsing such as wrong
        /// syntax used.
        /// </exception>
        /// <exception cref="TemplateCompilationException">
        /// If a bad dynamic language syntax is found such as
        /// a bad C# code syntax.
        /// </exception>
        public void Parse()
        {
            this.defaultInstance = new AtTemplateInstance(this);

            if (!string.IsNullOrEmpty(this.parser.TemplateFile))
            {
                using (StreamReader reader = new StreamReader(this.parser.TemplateFile, this.encoding))
                {
                    int c;
                    while ((c = reader.Read()) >= 0)
                    {
                        if ((char) c == '\n')
                        {
                            this.parser.LineEnding = "\n";
                            break;
                        }
                        else if ((char) c == '\r')
                        {
                            if ((c = reader.Read()) >= 0 && (char) c == '\n')
                            {
                                this.parser.LineEnding = "\r\n";
                            }
                            else
                            {
                                this.parser.LineEnding = "\r";
                            }
                            break;
                        }
                    }
                }

                this.parser.Reader = new StreamReader(this.parser.TemplateFile, this.encoding);
            }

            try
            {
                ParseTemplate();
                Compile();
                LoadAssembly();
            }
            finally
            {
                this.parser.Reader.Close();
            }
        }