本文整理汇总了C#中ILanguage.Initialize方法的典型用法代码示例。如果您正苦于以下问题:C# ILanguage.Initialize方法的具体用法?C# ILanguage.Initialize怎么用?C# ILanguage.Initialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILanguage
的用法示例。
在下文中一共展示了ILanguage.Initialize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Template
/// <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><% ... %></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>
/// "<%int n = 5; output.Write(5);%>"
/// </code>
/// </example>
/// You can combine text and code in a template String like this
/// <example>
/// <code>
/// "Hello, <%output.Write("World")%>!"
/// </code>
/// </example>
/// Code brackets can't be nested, otherwise <see cref="IncorrectSyntaxException">
/// will be thrown. You shouldn't use "$lt;%" and "%>"
/// </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);
}