本文整理汇总了C#中Build.Help方法的典型用法代码示例。如果您正苦于以下问题:C# Build.Help方法的具体用法?C# Build.Help怎么用?C# Build.Help使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Build
的用法示例。
在下文中一共展示了Build.Help方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
private static void Main(string[] args)
{
using (var build = new Build()
.Recognize(typeof(DotGraphController))
.Recognize(typeof(GraphController))
.Recognize(typeof(SerializeController)))
{
try
{
var parsedMethod = build.Parse(args);
if (parsedMethod.UnRecognizedArguments.Any())//Warning:
{
var unRecognizedArgumentsMessage = string.Format(
@"Unrecognized arguments:
{0}
Did you mean any of these arguments?
{1}", String.Join(",", parsedMethod.UnRecognizedArguments.Select(unrec => unrec.Value).ToArray()),
String.Join(",", parsedMethod.ArgumentWithOptions.Select(rec => rec.Name).ToArray()));
Console.WriteLine(unRecognizedArgumentsMessage);
Environment.Exit(1);
}
else
{
parsedMethod.Invoke(Console.Out);
}
}
catch (TypeConversionFailedException ex)
{
Console.WriteLine(String.Format("Could not convert argument {0} with value {1} to type {2}",
ex.Argument, ex.Value, ex.TargetType));
if (null != ex.InnerException)
{
Console.WriteLine("Inner exception: ");
Console.WriteLine(ex.InnerException.Message);
}
Environment.Exit(1);
}
catch (MissingArgumentException ex)
{
Console.WriteLine(String.Format("Missing argument(s): {0}", String.Join(", ", ex.Arguments.ToArray())));
if (build.RecognizesHelp)
Console.WriteLine(build.Help());
Environment.Exit(1);
}
#if DEBUG
catch (Exception ex1)
{
Console.WriteLine(string.Join(Environment.NewLine, new object[]
{
"The invokation failed with exception:",
ex1.Message, ex1.StackTrace
}));
Environment.Exit(1);
}
#endif
}
}
示例2: Main
static void Main(string[] args)
{
var path = Directory.GetParent(System.Reflection.Assembly.GetExecutingAssembly().Location)
.FullName;
using(var parserBuilder = new Build().ConfigurationFrom(
path))
{
try
{
var parsedMethod = parserBuilder.Parse(args);
if (parsedMethod.UnRecognizedArguments.Any())//Warning:
{
var unRecognizedArgumentsMessage = string.Format(
@"Unrecognized arguments:
{0}
Did you mean any of these arguments?
{1}", String.Join(",", parsedMethod.UnRecognizedArguments.Select(unrec => unrec.Value).ToArray()),
String.Join(",", parsedMethod.ArgumentWithOptions.Select(rec => rec.Argument.ToString()).ToArray()));
Console.WriteLine(unRecognizedArgumentsMessage);
}else
{
parsedMethod.Invoke(Console.Out);
}
}
catch (TypeConversionFailedException ex)
{
Console.WriteLine(String.Format("Could not convert argument {0} with value {1} to type {2}",
ex.Argument, ex.Value, ex.TargetType));
if (null!=ex.InnerException)
{
Console.WriteLine("Inner exception: ");
Console.WriteLine(ex.InnerException.Message);
}
}
catch (MissingArgumentException ex)
{
Console.WriteLine(String.Format("Missing argument(s): {0}",String.Join(", ",ex.Arguments.Select(a=>String.Format("{0}: {1}",a.Key,a.Value)).ToArray())));
if (parserBuilder.RecognizesHelp)
Console.WriteLine(parserBuilder.Help());
}
#if DEBUG
catch (Exception ex1)
{
Console.WriteLine( string.Join(Environment.NewLine, new object[]{
"The invokation failed with exception:",
ex1.Message, ex1.StackTrace}));
return;
}
#endif
}
}