本文整理汇总了C#中Options.FindVariable方法的典型用法代码示例。如果您正苦于以下问题:C# Options.FindVariable方法的具体用法?C# Options.FindVariable怎么用?C# Options.FindVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Options
的用法示例。
在下文中一共展示了Options.FindVariable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Format
private static void Format(TextWriter writer, string template, TextReader reader, Options options, Converter<string, Uri> wikiWordResolver)
{
Debug.Assert(writer != null);
Debug.Assert(template != null);
Debug.Assert(reader != null);
Debug.Assert(options != null);
WikiParser parser = new WikiParser();
parser.WikiWordResolver = wikiWordResolver;
NameValueCollection headers = new NameValueCollection();
IEnumerable<WikiToken> tokens = parser.Parse(reader, headers);
foreach (string key in headers)
options.Variables.Add(key, headers[key]);
string bodyName = MaskEmpty(options.BodyName, "body");
char[] buffer = template.ToCharArray();
int index = 0;
foreach (Match match in Regex.Matches(template, MaskEmpty(options.NamePattern, "$([A-Za-z_]+)"), RegexOptions.CultureInvariant))
{
writer.Write(buffer, index, match.Index - index);
string key = match.Groups[1].Value;
if (string.CompareOrdinal(key, bodyName) == 0)
{
HtmlFormatter formatter = new HtmlFormatter();
formatter.Format(tokens, new XhtmlTextWriter(writer, " "));
}
else
{
// TODO: Add URL-encoding support
HttpUtility.HtmlEncode(options.FindVariable(key, key + "?"), writer);
}
index = match.Index + match.Length;
}
writer.Write(buffer, index, buffer.Length - index);
}
示例2: Run
private static void Run(Options options, IEnumerable<string> args)
{
Debug.Assert(options != null);
Debug.Assert(args != null);
if (options.TemplatePath.Length == 0)
throw new ApplicationException("Missing HTML template file path.");
TextReader reader = null;
TextWriter writer = null;
Converter<string, Uri> wikiWordResolver = null;
IEnumerator<string> arg = args.GetEnumerator();
try
{
string wikiPath = null;
string wikiExtension = null;
string htmlExtension = null;
if (arg.MoveNext())
{
string sourcePath = arg.Current;
if (sourcePath != "-")
{
options.Variables["title"] = options.FindVariable("title", Path.GetFileNameWithoutExtension(sourcePath));
wikiPath = Path.GetDirectoryName(sourcePath);
wikiExtension = Path.GetExtension(sourcePath);
reader = File.OpenText(sourcePath);
}
}
if (arg.MoveNext())
{
string targetPath = arg.Current;
if (targetPath != "-")
{
writer = File.CreateText(targetPath);
htmlExtension = Path.GetExtension(targetPath);
}
}
wikiPath = Mask.EmptyString(wikiPath, Environment.CurrentDirectory);
wikiExtension = wikiExtension ?? ".wiki";
htmlExtension = htmlExtension ?? ".html";
wikiWordResolver = delegate(string word)
{
string filename = word + Mask.EmptyString(htmlExtension, ".html");
if (File.Exists(Path.Combine(wikiPath, filename)))
return new Uri(filename, UriKind.Relative);
if (File.Exists(Path.Combine(wikiPath, word + wikiExtension)))
return new Uri(filename, UriKind.Relative);
return null;
};
Format(writer ?? Console.Out, File.ReadAllText(options.TemplatePath),
reader ?? Console.In, options, wikiWordResolver);
}
finally
{
if (reader != null)
reader.Close();
if (writer != null)
writer.Close();
}
}