Example #1
0
 /// <summary>
 ///     Initializes a new instance of a <c>Template</c> type and compiles the
 ///     user code if possible.
 /// </summary>
 /// <param name="templateString">
 ///     A template String. Can't be empty. Can contain user text and/or code.
 ///     User's code must be limited with special code brackets <c>&lt;% ... %&gt;</c>.
 ///     Correct template String examples:
 ///     <example>
 ///         This template String will be treated as a text.
 ///         <code>
 ///             "This text will be printed as is"
 ///         </code>
 ///     </example>
 ///     <example>
 ///         But this one will be treated as a code, that should be executed.
 ///         <code>
 ///             "&lt;%int n = 5; output.Write(5);%&gt;"
 ///         </code>
 ///     </example>
 ///     You can combine text and code in a template String like this
 ///     <example>
 ///         <code>
 ///             "Hello, &lt;%output.Write("World")%&gt;!"
 ///         </code>
 ///     </example>
 ///     Code brackets can't be nested, otherwise <see cref="IncorrectSyntaxException">
 ///     will be thrown. You shouldn't use "$lt;%" and "%&gt;" 
 /// </param>
 /// <param name="namespaces">
 ///     It's a String[] array, that can contain required for code execution namespaces. 
 ///     Can be null.
 ///     <example>
 ///         <code>
 ///             new String[] { "System.Linq", "System.Threading.Tasks" }
 ///         </code>
 ///     </example>
 /// </param>
 /// <param name="assemblies">
 ///     It's a String[] array, that can contain required for code execution assemblies. 
 ///     Can be null.
 ///     <example>
 ///         <code>
 ///             new String[] { "System.Core.dll" }
 ///         </code>
 ///     </example>
 /// </param>
 /// <param name="language">
 ///     Some <see cref="ILanguage"/> implementation should be passed 
 ///     in order to execute user code. 
 ///     <c>Can't be null.</c>
 /// </param>
 /// <exception cref="ArgumentNullException">
 ///     If <paramref name="templateString"/> or
 ///     <paramref name="language"/> is <c>null</c>.
 /// </exception>
 /// <exception cref="IncorrectSyntaxException">
 ///     If <paramref name="templateString"/> has incorrect synatax.
 /// </exception>
 public Template(String templateString, String[] namespaces, String[] assemblies, ILanguage language)
 {
     if (templateString == null)
     {
         throw new ArgumentNullException("templateString");
     }
     if (language == null)
     {
         throw new ArgumentNullException("language");
     }
     this.language = language;
     var templateParser = new TemplateParser(language);
     String templateCode = templateParser.Parse(templateString);
     language.Initialize(templateCode, namespaces, assemblies);
 }