本文整理汇总了C#中StringTemplate类的典型用法代码示例。如果您正苦于以下问题:C# StringTemplate类的具体用法?C# StringTemplate怎么用?C# StringTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StringTemplate类属于命名空间,在下文中一共展示了StringTemplate类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Basic
static void Basic()
{
StringTemplate stringTemplate = new StringTemplate("hello <data>");
stringTemplate.Add("data", "world");
Console.WriteLine(stringTemplate.Render());
}
开发者ID:AdrianToman1,项目名称:StringTemplateEngine,代码行数:7,代码来源:Program.cs
示例2: Apply
//= null
public static string Apply(string template, Dictionary<string, object> @params )
{
StringTemplate st = new StringTemplate(template);
AddDefaultAttributes(st);
if (@params != null) AddAttributes(st, @params);
return st.ToString();
}
开发者ID:moscrif,项目名称:ide,代码行数:8,代码来源:FileTemplateUtilities.cs
示例3: StringTemplateView
public StringTemplateView(StringTemplate template)
{
//null check
if (template == null) throw new ArgumentNullException("template");
//set template
_template = template;
}
开发者ID:shayfriedman,项目名称:AspNetMvcViewEnginesSamples,代码行数:8,代码来源:StringTemplateView.cs
示例4: TestStringTemplate
static void TestStringTemplate()
{
string text = "$entity.Account$您好!<br/> 请点击连接重置您的秘密<br><a href=\"$url$\">$url$</a>";
StringTemplate st = new StringTemplate(text);
st.SetAttribute("entity", new Demo() { Account = "fengpengbin" });
st.SetAttribute("url", "http://www.aporeboy.com/vail");
Console.WriteLine(st.ToString());
}
开发者ID:fengpb,项目名称:CodeNote,代码行数:8,代码来源:Program.cs
示例5: Populate
public string Populate(ParameterSet parameterSet)
{
var t = new StringTemplate()
{
Text = Text,
};
return t.Populate(parameterSet.Parameters);
}
开发者ID:John-Leitch,项目名称:GenomeDotNet,代码行数:9,代码来源:BatchScriptTemplate.cs
示例6: Export
public string Export(IList dbObjects, string templatePath)
{
StringTemplate template = new StringTemplate();
var text = File.ReadAllText(templatePath);
//remove all tabs - it used only to format template code, not output code
template.Template = text.Replace("\t", "");
template.SetAttribute("dbObjects", dbObjects);
var output = template.ToString();
return output;
}
开发者ID:vansickle,项目名称:dbexplorer,代码行数:14,代码来源:AbstractTextExporter.cs
示例7: Template
public Template(string name)
{
var assembly = Assembly.GetCallingAssembly();
var stream = assembly.GetManifestResourceStream(name);
if (stream == null)
{
var candidates = string.Join(", ", assembly.GetManifestResourceNames());
throw new FileNotFoundException(string.Format("cannot find embedded resource {0} in assembly {1}, candidate templates include [{2}]", name, assembly.GetName(), candidates));
}
var contents = new StreamReader(stream).ReadToEnd();
template = new StringTemplate(contents);
}
开发者ID:camswords,项目名称:custom-soap-webservice,代码行数:14,代码来源:Template.cs
示例8: Generate
public static string Generate(string input, Dictionary<string, object> data)
{
var template = new StringTemplate(input);
foreach (var d in data)
template.SetAttribute(d.Key, d.Value);
string result = template.ToString();
;
template.Reset();
data.Clear();
template = null;
return result;
}
开发者ID:Kayomani,项目名称:FAP,代码行数:14,代码来源:TemplateEngine.cs
示例9: ListIterator_MultipleItems
public void ListIterator_MultipleItems()
{
// Arrange
var template = new StringTemplate("$user:{ u | <p>$u.FirstName$ is a super user? $u.IsSuperUser$. But his last name is $u.LastName$.</p>}$");
var user = new { FirstName = "Ian", LastName = "Robinson", IsSuperUser = false };
var userList = (new[] {user}).ToList();
userList.Add(new { FirstName = "Gertrude", LastName = "Schmuckbucket", IsSuperUser = true});
template.SetAttribute("user", userList);
// Act
var renderedText = template.ToString();
// Assert
Assert.AreEqual(renderedText, "<p>Ian is a super user? False. But his last name is Robinson.</p><p>Gertrude is a super user? True. But his last name is Schmuckbucket.</p>");
}
开发者ID:irobinson,项目名称:BeerCollectionMVP,代码行数:16,代码来源:StringTemplateUsageExamples.cs
示例10: ListIterator_SingleItem
public void ListIterator_SingleItem()
{
// Arrange
var template = new StringTemplate("$user:{ u | $u.FirstName$ is a super user? $u.IsSuperUser$. But his last name is $u.LastName$.}$");
template.SetAttribute("user", new
{
FirstName = "Ian",
LastName = "Robinson",
IsSuperUser = false
});
// Act
var renderedText = template.ToString();
// Assert
Assert.AreEqual(renderedText, "Ian is a super user? False. But his last name is Robinson.");
}
开发者ID:irobinson,项目名称:BeerCollectionMVP,代码行数:16,代码来源:StringTemplateUsageExamples.cs
示例11: GetParserCreationTemplate
public override StringTemplate GetParserCreationTemplate()
{
StringTemplate createParserST =
new StringTemplate(
" Profiler2 profiler = new Profiler2();\n" +
" $parserName$ parser = new $parserName$(tokens,profiler);\n" +
" profiler.setParser(parser);\n"
);
if ( !Debug )
{
createParserST =
new StringTemplate(
" $parserName$ parser = new $parserName$(tokens);\n"
);
}
return createParserST;
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:19,代码来源:JavaRuntimeTestHarness.cs
示例12: NestedProperties
public void NestedProperties()
{
// Arrange
IDictionary<string, object> ret = new Dictionary<string, object>();
ret["elem1"] = true;
ret["elem2"] = false;
var nestedObj = new Dictionary<string, object>();
nestedObj["nestedProp"] = 100;
ret["elem3"] = nestedObj;
var template = new StringTemplate("$elem1$ or $elem2$ and value: $elem3.nestedProp$") { Attributes = ret };
// Act
var renderedText = template.ToString();
// Assert
Assert.AreEqual(renderedText, "True or False and value: 100");
}
开发者ID:irobinson,项目名称:BeerCollectionMVP,代码行数:19,代码来源:StringTemplateUsageExamples.cs
示例13: AddAttributes
public static void AddAttributes(StringTemplate st, Dictionary<string, object> @params)
{
foreach(string key in @params.Keys) {
object val = @params[key];
if (val != null) {
if (val is string && String.IsNullOrEmpty(val as string))
continue;
/*
if (val is ArrayList)
{
//st.SetAttribute(key, (val as ArrayList).ToArray());
ArrayList al = val as ArrayList;
foreach (object o in al)
st.SetAttribute(key, o);
}
else
*/
st.SetAttribute(key, val);
}
}
}
开发者ID:moscrif,项目名称:ide,代码行数:21,代码来源:FileTemplateUtilities.cs
示例14: GetLexerTestFileTemplate
public override StringTemplate GetLexerTestFileTemplate()
{
StringTemplate outputFileST = new StringTemplate(
"import org.antlr.runtime.*;\n" +
"import org.antlr.runtime.tree.*;\n" +
"import org.antlr.runtime.debug.*;\n" +
"\n" +
"class Profiler2 extends Profiler {\n" +
" public void terminate() { ; }\n" +
"}\n" +
"public class Test {\n" +
" public static void main(String[] args) throws Exception {\n" +
" CharStream input = new ANTLRFileStream(args[0]);\n" +
" $lexerName$ lex = new $lexerName$(input);\n" +
" CommonTokenStream tokens = new CommonTokenStream(lex);\n" +
" System.out.println(tokens);\n" +
" }\n" +
"}"
);
return outputFileST;
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:22,代码来源:JavaRuntimeTestHarness.cs
示例15: StringTemplatAddDuplicateSameValuesTest
public void StringTemplatAddDuplicateSameValuesTest()
{
target = new StringTemplate(String.Empty);
target.Add("test", "one");
try
{
target.Add("test", "one");
Assert.Fail("No exception thrown");
}
catch (ArgumentException exception)
{
Assert.AreEqual("Element has already been added.\r\nParameter name: element", exception.Message);
Assert.AreEqual("element", exception.ParamName);
}
catch
{
Assert.Fail("ArgumentException not thrown");
}
}
开发者ID:AdrianToman1,项目名称:StringTemplateEngine,代码行数:22,代码来源:StringTemplateUnitTests.cs
示例16: ToString
public override string ToString()
{
Tests = Enumerable
.Range(0, TestCount)
.Select(x => "test" + x)
.Join(", ");
InstructionCompleteCasesText = InstructionCompleteCases
.Select(x => string.Format(
@"
{0}:
begin
{1}
end
",
x.Key,
x.Value))
.JoinLines();
var template = File.ReadAllText(PathHelper.GetExecutingPath(@"McuTestTemplate.v"));
var t = new StringTemplate(template).PopulateObj(this);
return t;
}
开发者ID:John-Leitch,项目名称:Blue-Racer-CPU,代码行数:24,代码来源:McuTestTemplate.cs
示例17: GetTreeTestFileTemplate
public override StringTemplate GetTreeTestFileTemplate()
{
StringTemplate outputFileST = new StringTemplate(
"import org.antlr.runtime.*;\n" +
"import org.antlr.runtime.tree.*;\n" +
"import org.antlr.runtime.debug.*;\n" +
"\n" +
"class Profiler2 extends Profiler {\n" +
" public void terminate() { ; }\n" +
"}\n" +
"public class Test {\n" +
" public static void main(String[] args) throws Exception {\n" +
" CharStream input = new ANTLRFileStream(args[0]);\n" +
" $lexerName$ lex = new $lexerName$(input);\n" +
" TokenRewriteStream tokens = new TokenRewriteStream(lex);\n" +
" $createParser$\n" +
" $parserName$.$parserStartRuleName$_return r = parser.$parserStartRuleName$();\n" +
" $if(!treeParserStartRuleName)$\n" +
" if ( r.tree!=null ) {\n" +
" System.out.println(((Tree)r.tree).toStringTree());\n" +
" ((CommonTree)r.tree).sanityCheckParentAndChildIndexes();\n" +
" }\n" +
" $else$\n" +
" CommonTreeNodeStream nodes = new CommonTreeNodeStream((Tree)r.tree);\n" +
" nodes.setTokenStream(tokens);\n" +
" $treeParserName$ walker = new $treeParserName$(nodes);\n" +
" walker.$treeParserStartRuleName$();\n" +
" $endif$\n" +
" }\n" +
"}"
);
return outputFileST;
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:34,代码来源:JavaRuntimeTestHarness.cs
示例18: GetEmbeddedInstanceOf
public virtual StringTemplate GetEmbeddedInstanceOf( StringTemplate enclosingInstance,
string name )
{
//Console.Out.WriteLine( "surrounding group is " +
// enclosingInstance.Group.Name +
// " with native group " + enclosingInstance.NativeGroup.Name );
StringTemplate st = null;
// TODO: seems like this should go into lookupTemplate
if ( name.StartsWith( "super." ) )
{
// for super.foo() refs, ensure that we look at the native
// group for the embedded instance not the current evaluation
// group (which is always pulled down to the original group
// from which somebody did group.getInstanceOf("foo");
st = enclosingInstance.NativeGroup.GetInstanceOf( enclosingInstance, name );
}
else
{
st = GetInstanceOf( enclosingInstance, name );
}
// make sure all embedded templates have the same group as enclosing
// so that polymorphic refs will start looking at the original group
st.Group = this;
st.EnclosingInstance = enclosingInstance;
return st;
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:26,代码来源:StringTemplateGroup.cs
示例19: EmitTemplateStopDebugString
public virtual void EmitTemplateStopDebugString( StringTemplate st,
IStringTemplateWriter @out )
{
if ( _noDebugStartStopStrings == null ||
!_noDebugStartStopStrings.Contains( st.Name ) )
{
string groupPrefix = "";
if ( !st.Name.StartsWith( "if" ) && !st.Name.StartsWith( "else" ) )
{
if ( st.NativeGroup != null )
{
groupPrefix = st.NativeGroup.Name + ".";
}
else
{
groupPrefix = st.Group.Name + ".";
}
}
@out.Write( "</" + groupPrefix + st.Name + ">" );
}
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:21,代码来源:StringTemplateGroup.cs
示例20: DefineRegionTemplate
/** <summary>Track all references to regions <@foo>...<@end> or <@foo()>.</summary> */
public virtual StringTemplate DefineRegionTemplate( StringTemplate enclosingTemplate,
string regionName,
string template,
RegionType type )
{
StringTemplate regionST =
DefineRegionTemplate( enclosingTemplate.OutermostName,
regionName,
template,
type );
enclosingTemplate.OutermostEnclosingInstance.AddRegionName( regionName );
return regionST;
}
开发者ID:mahanteshck,项目名称:antlrcs,代码行数:14,代码来源:StringTemplateGroup.cs
注:本文中的StringTemplate类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论