本文整理汇总了C#中Template.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Template.Add方法的具体用法?C# Template.Add怎么用?C# Template.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Template
的用法示例。
在下文中一共展示了Template.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMessageTemplate
public virtual Template GetMessageTemplate(bool verbose)
{
Template messageST = new Template(GetErrorType().msg);
messageST.impl.Name = errorType.Name;
messageST.Add("verbose", verbose);
object[] args = GetArgs();
for (int i = 0; i < args.Length; i++)
{
string attr = "arg";
if (i > 0)
attr += i + 1;
messageST.Add(attr, args[i]);
}
if (args.Length < 2)
messageST.Add("arg2", null); // some messages ref arg2
Exception cause = GetCause();
if (cause != null)
{
messageST.Add("exception", cause);
messageST.Add("stackTrace", cause.StackTrace);
}
else
{
messageST.Add("exception", null); // avoid ST error msg
messageST.Add("stackTrace", null);
}
return messageST;
}
示例2: Visit
public override Template Visit(Root root)
{
Template template = new Template("#include \"<header>\"\n\n<body>");
template.Add("header", this.HeaderFileName);
template.Add("body", root.Block.Accept(this));
return template;
}
示例3: Visit
public override Template Visit(TemplateType type)
{
Template template = new Template("<type>\\<<list; separator=\", \">>");
template.Add("type", type.Type.Accept(this));
template.Add("list", type.Args.Select(x => x.Accept(this)));
return template;
}
示例4: GenerateMain
public static void GenerateMain(string entryType, string entryNamespace, bool inputArgs)
{
StreamWriter writer = new StreamWriter(FileWritterManager.WorkingPath + "main.cpp");
string txt;
Template template;
string altTools = Environment.GetEnvironmentVariable("ALTERNATIVE_TOOLS_PATH");
if(altTools == null)
altTools = Path.Combine(Environment.CurrentDirectory, (@"..\..\..\Tools").Replace('\\','/'));
StreamReader sr = new StreamReader((altTools + @"\Templates\Code\main.stg").Replace('\\', '/'));
txt = sr.ReadToEnd();
template = new Template(txt);
StreamReader fs = new StreamReader(Path.Combine(altTools, "Text/notice"));
string notice = fs.ReadToEnd();
template.Add("NOTICE", notice);
template.Add("ENTRY_TYPE", entryType);
template.Add("ENTRY_NAMESPACE_NEEDED", !String.IsNullOrEmpty(entryNamespace));
template.Add("ENTRY_NAMESPACE", entryNamespace);
template.Add("INPUT_ARGS", inputArgs);
string output = template.Render();
writer.Write(output);
writer.Flush();
writer.Close();
FileWritterManager.AddSourceFile("main.cpp");
}
示例5: TestIndirectProp
public void TestIndirectProp()
{
string template = "<u.(propname)>: <u.name>";
Template st = new Template(template);
st.Add("u", new TestCoreBasics.User(1, "parrt"));
st.Add("propname", "id");
string expected = "1: parrt";
string result = st.Render();
Assert.AreEqual(expected, result);
}
示例6: TestCatArrayAndSingleAttribute
public void TestCatArrayAndSingleAttribute()
{
// replace first of yours with first of mine
Template e = new Template(
"<[mine,yours]; separator=\", \">"
);
e.Add("mine", new string[] { "1", "2", "3" });
e.Add("yours", "a");
string expecting = "1, 2, 3, a";
Assert.AreEqual(expecting, e.Render());
}
示例7: TestCat2Attributes
public void TestCat2Attributes()
{
Template e = new Template(
"<[names,phones]; separator=\", \">"
);
e.Add("names", "Ter");
e.Add("names", "Tom");
e.Add("phones", "1");
e.Add("phones", "2");
string expecting = "Ter, Tom, 1, 2";
Assert.AreEqual(expecting, e.Render());
}
示例8: TestCat2AttributesWithApply
public void TestCat2AttributesWithApply()
{
Template e = new Template(
"<[names,phones]:{a|<a>.}>"
);
e.Add("names", "Ter");
e.Add("names", "Tom");
e.Add("phones", "1");
e.Add("phones", "2");
string expecting = "Ter.Tom.1.2.";
Assert.AreEqual(expecting, e.Render());
}
示例9: TestCatArrayAndEmptyAttributes2
public void TestCatArrayAndEmptyAttributes2()
{
// + is overloaded to be cat strings and cat lists so the
// two operands (from left to right) determine which way it
// goes. In this case, x+mine is a list so everything from their
// to the right becomes list cat.
Template e = new Template(
"<[x,mine,y,yours,z]; separator=\", \">"
);
e.Add("mine", new string[] { "1", "2", "3" });
e.Add("yours", "a");
string expecting = "1, 2, 3, a";
Assert.AreEqual(expecting, e.Render());
}
示例10: Visit
public override Template Visit(GlobalBlock block)
{
Template template = new Template("<list; separator=\"\n\">");
List<Template> list = new List<Template>();
bool last = false;
AstNode last_node = null;
foreach (var node in block.List)
{
// Generic Class/Function Should Defined in Header File
if (node is FuncDef && ((FuncDef)node).GenericParameter.Count() > 0) continue;
if (node is Class && ((Class)node).GenericParameter.Count() > 0) continue;
if (node is GlobalAlloc && node.Attribute.Exists(x => x.Name == "const") && !node.Attribute.Exists(x => x.Name == "static")) continue;
if (node.Attribute.Exists(x => x.Name == "extern")) continue;
if (node is Import || node is GlobalUsing || node is GlobalTypeDef || (node is Enum && node.Attribute.All(x => x.Name != "ToString"))) continue;
bool current = node is FuncDef || node is Class || node is Enum || node is Import || node is GlobalUsing || node is Namespace;
if ((last || current) && !(last_node is Import && node is Import))
{
Template tp = new Template("\n<node>");
tp.Add("node", node.Accept(this));
list.Add(tp);
}
else
{
list.Add(node.Accept(this));
}
last = current;
last_node = node;
}
template.Add("list", list);
return template;
}
示例11: TestAlternateDelimiter
public void TestAlternateDelimiter()
{
var template = new Template("hello ~token~.", '~', '~');
template.Add("token", "world");
var output = template.Render();
Assert.AreEqual("hello world.", output);
}
示例12: TestConditional_NotNull
public void TestConditional_NotNull()
{
var template = new Template("$if(value)$yes$endif$", '$', '$');
template.Add("value", "Some Object");
var output = template.Render();
Assert.AreEqual("yes", output);
}
示例13: TestConditional_True
public void TestConditional_True()
{
var template = new Template("$if(value)$yes$endif$", '$', '$');
template.Add("value", true);
var output = template.Render();
Assert.AreEqual("yes", output);
}
示例14: ExpandMacros
/// <summary>
/// Expands the macros in the given string using the variables stored inside
/// this object. The resulting string will have the macros expanded.
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>The output string with macros expanded.</returns>
public string ExpandMacros(string input)
{
// If we have a null, then just return a null.
if (string.IsNullOrWhiteSpace(input))
{
return input;
}
// We have to repeatedly run through the macros since we have macros
// that expand into other macros.
string results = input;
while (results.IndexOf('{') >= 0)
{
// Create a template with all of the variables inside it.
var template = new Template(results, '{', '}');
foreach (KeyValuePair<string, string> macro in Substitutions)
{
template.Add(macro.Key, macro.Value);
}
// Render out the template to the results.
results = template.Render();
}
// Return the resulting string.
return results;
}
示例15: TestDefaultDelimiter
public void TestDefaultDelimiter()
{
var template = new Template("hello <token>.");
template.Add("token", "world");
var output = template.Render();
Assert.AreEqual("hello world.", output);
}