本文整理汇总了C#中FormatCompiler类的典型用法代码示例。如果您正苦于以下问题:C# FormatCompiler类的具体用法?C# FormatCompiler怎么用?C# FormatCompiler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FormatCompiler类属于命名空间,在下文中一共展示了FormatCompiler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestCompile_CommentAloneOnlyLine_PrintsSurroundingSpace
public void TestCompile_CommentAloneOnlyLine_PrintsSurroundingSpace()
{
FormatCompiler compiler = new FormatCompiler();
Generator generator = compiler.Compile(" {{#! comment }} ");
string result = generator.Render(null);
Assert.AreEqual(" ", result, "The wrong text was generated.");
}
示例2: TestCompile_CommentContentComment_RemovesComment
public void TestCompile_CommentContentComment_RemovesComment()
{
FormatCompiler compiler = new FormatCompiler();
const string format = "{{#! comment }}Middle{{#! comment }}";
Generator generator = compiler.Compile(format);
string result = generator.Render(new object());
Assert.AreEqual("Middle", result, "The wrong text was generated.");
}
示例3: TestCompile_Key_ReplacesWithValue
public void TestCompile_Key_ReplacesWithValue()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"Hello, {{Name}}!!!";
Generator generator = compiler.Compile(format);
string result = generator.Render(new { Name = "Bob" });
Assert.AreEqual("Hello, Bob!!!", result, "The wrong text was generated.");
}
示例4: TestCompile_LineAllWhitespace_PrintsWhitespace
public void TestCompile_LineAllWhitespace_PrintsWhitespace()
{
FormatCompiler compiler = new FormatCompiler();
const string format = "\t \t";
Generator generator = compiler.Compile(format);
string result = generator.Render(null);
Assert.AreEqual(format, result, "The generated text was wrong.");
}
示例5: TestCompile_NoTags_PrintsFormatString
public void TestCompile_NoTags_PrintsFormatString()
{
FormatCompiler compiler = new FormatCompiler();
const string format = "This is an ordinary string.";
Generator generator = compiler.Compile(format);
string result = generator.Render(null);
Assert.AreEqual(format, result, "The generated text was wrong.");
}
示例6: TestCompile_CommentBlankComment_RemovesLine
public void TestCompile_CommentBlankComment_RemovesLine()
{
FormatCompiler compiler = new FormatCompiler();
const string format = "{{#! comment }} {{#! comment }}";
Generator generator = compiler.Compile(format);
string result = generator.Render(new object());
Assert.AreEqual(String.Empty, result, "The wrong text was generated.");
}
示例7: TestCompile_CanUseContextVariablesToMakeDecisions
public void TestCompile_CanUseContextVariablesToMakeDecisions()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#each this}}{{#if @index}}{{#index}}{{/if}}{{/each}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new int[] { 1, 1, 1, 1, });
string expected = "123";
Assert.AreEqual(expected, actual, "The numbers were not valid.");
}
示例8: TestCompile_CanUseContextStartEndVariablesToMakeDecisions
public void TestCompile_CanUseContextStartEndVariablesToMakeDecisions()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#each this}}{{#if @start}}<li class=""first""></li>{{#elif @end}}<li class=""last""></li>{{#else}}<li class=""middle""></li>{{/if}}{{/each}}";
Generator generator = compiler.Compile(format);
string actual = generator.Render(new int[] { 1, 1, 1, 1, });
string expected = @"<li class=""first""></li><li class=""middle""></li><li class=""middle""></li><li class=""last""></li>";
Assert.AreEqual(expected, actual, "The string is not valid.");
}
示例9: TestCompile_CommentNewLineBlank_PrintsBlank
public void TestCompile_CommentNewLineBlank_PrintsBlank()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @" {{#! comment }}
";
Generator generator = compiler.Compile(format);
string result = generator.Render(null);
Assert.AreEqual(" ", result, "The wrong text was generated.");
}
示例10: TestCompile_OutputNewLineBlank_PrintsBothLines
public void TestCompile_OutputNewLineBlank_PrintsBothLines()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"Hello{{#newline}}
";
const string expected = @"Hello
";
Generator generator = compiler.Compile(format);
string result = generator.Render(null);
Assert.AreEqual(expected, result, "The wrong text was generated.");
}
示例11: TestCompile_CanUseContextVariableToToggle
public void TestCompile_CanUseContextVariableToToggle()
{
FormatCompiler compiler = new FormatCompiler();
const string format = @"{{#set even}}{{#each this}}{{#if @even}}Even {{#else}}Odd {{/if}}{{#set even}}{{/each}}";
Generator generator = compiler.Compile(format);
generator.ValueRequested += (sender, e) =>
{
e.Value = !(bool)(e.Value ?? false);
};
string actual = generator.Render(new int[] { 1, 1, 1, 1 });
string expected = "Even Odd Even Odd ";
Assert.AreEqual(expected, actual, "The context variable was not toggled.");
}
示例12: TestEach
public void TestEach()
{
Dictionary<string, object> allparameters = new Dictionary<string, object>();
allparameters.Add("stuName", "Jason");
allparameters.Add("schoolName", "SH LJZ");
//-----------------------------------------------------
var class1 = new Dictionary<string, object>();
class1.Add("Address", "Tong ren road 258号");
class1.Add("Date", DateTime.Now);
var Class2 = new Dictionary<string, object>();
Class2.Add("Address", "People square");
Class2.Add("Date", DateTime.Now);
List<object> classes = new List<object>();
classes.Add(class1);
classes.Add(Class2);
//-------------------------------------------------------
allparameters.Add("Classes", classes);
//--------------------------------------------------------
var school1 = new Dictionary<string, object>();
school1.Add("SchoolName", "LJZ");
school1.Add("StuCount", 10);
var school2 = new Dictionary<string, object>();
school2.Add("SchoolName", "PSQ");
school2.Add("StuCount", "20");
List<object> schools = new List<object>();
schools.Add(school1);
schools.Add(school2);
//---------------------------------------------------------
allparameters.Add("Schools", schools);
FormatCompiler compiler = new FormatCompiler();
Generator generator = compiler.Compile(template);
string actual = generator.Render(allparameters);
Assert.IsNotNull(actual);
}
示例13: TestCompile_IfElse_TwoElses_IncludesSecondElseInElse_Throws
public void TestCompile_IfElse_TwoElses_IncludesSecondElseInElse_Throws()
{
FormatCompiler parser = new FormatCompiler();
const string format = "Before{{#if this}}Yay{{#else}}Nay{{#else}}Bad{{/if}}After";
Generator generator = parser.Compile(format);
string result = generator.Render(false);
Assert.AreEqual("BeforeNay{{#else}}BadAfter", result, "The wrong text was generated.");
}
示例14: TestCompile_IfElse_EvaluatesToFalse_PrintsElse
public void TestCompile_IfElse_EvaluatesToFalse_PrintsElse()
{
FormatCompiler parser = new FormatCompiler();
const string format = "Before{{#if this}}Yay{{#else}}Nay{{/if}}After";
Generator generator = parser.Compile(format);
string result = generator.Render(false);
Assert.AreEqual("BeforeNayAfter", result, "The wrong text was generated.");
}
示例15: TestCompile_IfElif_ElifFalse_PrintsNothing
public void TestCompile_IfElif_ElifFalse_PrintsNothing()
{
FormatCompiler parser = new FormatCompiler();
const string format = "Before{{#if First}}First{{#elif Second}}Second{{/if}}After";
Generator generator = parser.Compile(format);
string result = generator.Render(new { First = false, Second = false });
Assert.AreEqual("BeforeAfter", result, "The wrong text was generated.");
}