本文整理汇总了C#中Parser.RunStatic方法的典型用法代码示例。如果您正苦于以下问题:C# Parser.RunStatic方法的具体用法?C# Parser.RunStatic怎么用?C# Parser.RunStatic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser.RunStatic方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var p = new Parser(typeof(Options));
p.Register.HelpHandler("help,h,?", Console.WriteLine);
p.Register.ParameterHandler("debug", () => System.Diagnostics.Debugger.Launch());
p.Register.ErrorHandler(context => {
if (context.Exception is CommandLineParserException)
Console.Write("{0}.\n{1}\n", context.Exception.Message, Options.HelpText);
else
context.ReThrow = true; });
p.RunStatic(args);
}
示例2: Execute_HandleError_Registered_Rethrow
public void Execute_HandleError_Registered_Rethrow()
{
var p = new Parser<Sample_39>();
var handled = false;
p.Register.ErrorHandler(ex =>
{
handled = true;
ex.ReThrow = true;
});
Expect(() => p.RunStatic(new string[] {}),
Throws.InstanceOf<Exception>());
Expect(handled, Is.True);
}
示例3: Execute_HandleError_Registered_NoRethrow
public void Execute_HandleError_Registered_NoRethrow()
{
var p = new Parser<Sample_39>();
var handled = false;
p.Register.ErrorHandler(ex =>
{
handled = true;
});
p.RunStatic(new string[] { });
Expect(handled, Is.True);
}
示例4: Empty_Defined_NotStatic_TargetNull_Exception
public void Empty_Defined_NotStatic_TargetNull_Exception()
{
var p = new Parser<Sample_15>();
Expect(() => p.RunStatic(new string[] {}),
Throws.InstanceOf<ParserExecutionTargetException>());
}
示例5: EmptyHandler_Static_CalledWhenNoArgs
public void EmptyHandler_Static_CalledWhenNoArgs()
{
var mock = new Mock<IPrinter>();
Sample_16.StaticPrinter = mock.Object;
var p = new Parser<Sample_16>();
p.RunStatic(new string[] { });
mock.Verify(o => o.Print("a"));
Sample_16.StaticPrinter = null;
}
示例6: Run_Verb_NoMatchingMethod_Exception
public void Run_Verb_NoMatchingMethod_Exception()
{
var p = new Parser<Sample_25>();
Expect(() => p.RunStatic(new[] { "boo!" }), Throws.InstanceOf<VerbNotFoundException>());
}
示例7: Run_NoVerb_NoDefaultVerb_Exception
public void Run_NoVerb_NoDefaultVerb_Exception()
{
var p = new Parser<Sample_25>();
Expect(() => p.RunStatic(new[] { "-x" }), Throws.InstanceOf<MissingDefaultVerbException>());
}
示例8: RegisterEmptyHelpHandler_EmptyArguments_Called
public void RegisterEmptyHelpHandler_EmptyArguments_Called()
{
var p = new Parser<Sample_25>();
string help = null;
p.Register.EmptyHelpHandler(h => help = h);
Expect(help, Is.Null);
p.RunStatic(new string[] { });
Expect(help, Is.Not.Null);
}
示例9: Help_Static
public void Help_Static()
{
var mock = new Mock<IPrinter>();
Sample_22.StaticPrinter = mock.Object;
var p = new Parser<Sample_22>();
p.RunStatic(new[] { "-?" });
Sample_22.StaticPrinter = null;
}
示例10: Help_NonStatic_CalledWithNull_Exception
public void Help_NonStatic_CalledWithNull_Exception()
{
var p = new Parser<Sample_23>();
p.RunStatic(new[] { "-?" });
}
示例11: Execute_HandleError_Registered_Rethrow
public void Execute_HandleError_Registered_Rethrow()
{
var p = new Parser<Sample_39>();
var handled = false;
p.Register.ErrorHandler(ex =>
{
handled = true;
ex.ReThrow = true;
});
try
{
p.RunStatic(new string[] { });
Assert.Fail();
}
catch (Exception)
{
Assert.IsTrue(handled);
}
}
示例12: Execute_HandleError_Registered_DefaultNoRethrow
public void Execute_HandleError_Registered_DefaultNoRethrow()
{
var p = new Parser<Sample_39>();
var handled = false;
p.Register.ErrorHandler(ex =>
{
handled = true;
});
p.RunStatic(new string[] { });
Assert.IsTrue(handled);
}
示例13: Empty_Defined_NotStatic_TargetNull_Exception
public void Empty_Defined_NotStatic_TargetNull_Exception()
{
var p = new Parser<Sample_15>();
p.RunStatic(new string[] { });
}
示例14: Run_Verb_NoMatchingMethod_Exception
public void Run_Verb_NoMatchingMethod_Exception()
{
var p = new Parser<Sample_25>();
p.RunStatic(new[] { "boo!" });
}
示例15: Run_NoVerb_NoDefaultVerb_Exception
public void Run_NoVerb_NoDefaultVerb_Exception()
{
var p = new Parser<Sample_25>();
p.RunStatic(new string[] { "-x" });
}