本文整理汇总了C#中Processor.FormatString方法的典型用法代码示例。如果您正苦于以下问题:C# Processor.FormatString方法的具体用法?C# Processor.FormatString怎么用?C# Processor.FormatString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Processor
的用法示例。
在下文中一共展示了Processor.FormatString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestFormatter
public void TestFormatter()
{
var processor = new Processor();
processor.AddDomain("TestDomain");
processor.AddDomain("TestDomain", "SubDomain");
processor.GetDomain("TestDomain").Add("TestKey", "This is a test.");
processor.GetDomain("TestDomain", "SubDomain").Add("TestKey", "This is a subdomain test.");
var formatStr1 = "##TestDomain.TestKey##";
var formatOut1 = processor.FormatString(formatStr1);
var formatStr2 = "##TestDomain:SubDomain.TestKey##";
var formatOut2 = processor.FormatString(formatStr2);
var formatStr3 = "##TestDomain.TestKey####TestDomain:SubDomain.TestKey##";
var formatOut3 = processor.FormatString(formatStr3);
Assert.AreEqual("This is a test.", formatOut1);
Assert.AreEqual("This is a subdomain test.", formatOut2);
Assert.AreEqual("This is a test.This is a subdomain test.", formatOut3);
}
示例2: TestFormatterWithNewlineOptionsAndSameReplacers
public void TestFormatterWithNewlineOptionsAndSameReplacers()
{
var processor = new Processor();
processor.AddDomain("TestDomain");
processor.GetDomain("TestDomain").Add("TestKey", "This is a test.");
var formatStr = @"<@<% TestOption test=""Parameter"" %>@>
##TestDomain.TestKey##<% TestOption test=""Parameter"" %>##TestDomain.TestKey##";
var formatOut = processor.FormatString(formatStr);
Assert.AreEqual("This is a test.This is a test.", formatOut);
}
示例3: TestFormatterWithConvertersAndOptions
public void TestFormatterWithConvertersAndOptions()
{
var processor = new Processor();
processor.AddDomain("TestDomain");
processor.GetDomain("TestDomain").Add("TestKey", "This is a test.");
var formatStr = @"<@
<% Import dll=""NasuTek.Preprocessor.ProcessingLibrary.Tests.dll"" %>
<% Import namespace=""NasuTek.Preprocessor.ProcessingLibrary.Tests"" %>
@>
##TestDomain.TestKey(TestConverter[Demo=""Demo Testing "",Demo2=""Is Awesome.""])##";
processor.ExecuteProcessors(formatStr);
var formatOut = processor.FormatString(formatStr);
Assert.AreEqual("Demo Testing Is Awesome.", formatOut);
}
示例4: Main
static void Main(string[] args)
{
Console.Error.WriteLine("NasuTek Preprocessor Version 1.0");
Console.Error.WriteLine("\tCopyright (C) 2013 NasuTek Enterprises");
Console.Error.WriteLine();
var inFiles = new List<string>();
var outFiles = new List<string>();
var processorDefinitionFile = new List<string>();
var parameters = new List<string>();
string showHelp = null;
if (args.Length < 1)
showHelp = "";
var optionSet = new OptionSet {
{ "i|InFile=", "The filename to preprocess. Use STDIN to use standard input.", inFiles.Add },
{ "o|OutFile=", "The filename to write the processed file to. Use STDOUT to use standard output.", outFiles.Add },
{ "P|ProcessorDefinitionFile=", "The filename to preprocess. Use STDIN to use standard input.", processorDefinitionFile.Add },
{ "p|Parameter=", "Set a parameter for a processor.", parameters.Add },
{ "?|h|Help", "Shows Help", v=> showHelp = v },
};
try
{
optionSet.Parse(args);
}
catch (OptionException e)
{
Console.Error.Write("NasuTek.Preprocessor: ");
Console.Error.WriteLine(e.Message);
Console.Error.WriteLine("Try `NasuTek.Preprocessor /Help' for more information.");
return;
}
if (showHelp != null)
{
Show_Help(optionSet);
return;
}
#if !DEBUG
try
{
#endif
foreach (var inFileName in inFiles)
{
var processor = new Processor();
foreach (var v in parameters)
{
var splValComma = v.Split(',');
var splValEqual = splValComma[1].Split('=');
processor.SetParameter(splValComma[0], splValEqual[0], splValEqual[1]);
}
var input = "";
if (inFileName != "STDIN")
input = File.ReadAllText(inFileName);
else
{
try
{
#pragma warning disable 168
var tmp = Console.KeyAvailable;
#pragma warning restore 168
var readLine = "";
while (readLine != "__EOF__")
{
readLine = Console.ReadLine();
if (readLine != "__EOF__")
input += readLine + Environment.NewLine;
}
}
catch (InvalidOperationException)
{
input = Console.In.ReadToEnd();
}
}
foreach (var processorDef in processorDefinitionFile)
{
processor.ExecuteProcessors(File.ReadAllText(processorDef));
}
processor.ExecuteProcessors(input);
input = processor.FormatString(input);
if (outFiles[inFiles.IndexOf(inFileName)] != "STDOUT")
File.WriteAllText(outFiles[inFiles.IndexOf(inFileName)], input);
else
Console.Write(input);
}
#if !DEBUG
}
catch (Exception e)
{
if (Debugger.IsAttached)
//.........这里部分代码省略.........