本文整理汇总了C#中Option.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Option.Invoke方法的具体用法?C# Option.Invoke怎么用?C# Option.Invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option.Invoke方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleExecution
public void SimpleExecution()
{
bool hasRun = false;
Option o = new Option(new []{"r","run","doit"}, ()=>hasRun =true, "");
o.Invoke("r","");
Assert.IsTrue(hasRun);
}
示例2: SimpleExecutionWith_Double
public void SimpleExecutionWith_Double()
{
double result = 0;
Option o = new Option(new []{"r","run","doit"}, (double x)=>result=x, "value","");
o.Invoke("r","1.1");
Assert.AreEqual(1.1, result);
}
示例3: SimpleExecutionWith_Byte
public void SimpleExecutionWith_Byte()
{
byte result = 0;
Option o = new Option(new []{"r","run","doit"}, (byte x)=>result=x, "value","");
o.Invoke("r","240");
Assert.AreEqual(240, result);
}
示例4: SimpleExecutionWith_Bool
public void SimpleExecutionWith_Bool()
{
bool result = false;
Option o = new Option(new []{"r","run","doit"}, x=>result=x, "value","");
o.Invoke("r","True");
Assert.AreEqual(true, result);
}
示例5: SimpleExecutionWith_Short
public void SimpleExecutionWith_Short()
{
short result = 0;
Option o = new Option(new []{"r","run","doit"}, (short x)=>result=x, "value","");
o.Invoke("r","1");
Assert.AreEqual(1, result);
}
示例6: SimpleExecutionWith_Int
public void SimpleExecutionWith_Int()
{
int result = 0;
Option o = new Option((int x)=>result=x, "value","");
o.Invoke("","1");
Assert.AreEqual(1, result);
}
示例7: SimpleExecutionWith_TimeSpan
public void SimpleExecutionWith_TimeSpan()
{
TimeSpan result = TimeSpan.Zero;
Option o = new Option((TimeSpan x)=>result=x, "value","");
o.Invoke("",TimeSpan.FromDays(1.5).ToString());
Assert.AreEqual(TimeSpan.FromDays(1.5), result);
}
示例8: SimpleExecutionWith_DateTime
public void SimpleExecutionWith_DateTime()
{
DateTime result = DateTime.MinValue;
Option o = new Option((DateTime x)=>result=x, "value","");
o.Invoke("",DateTime.MaxValue.ToString("o"));
Assert.AreEqual(DateTime.MaxValue, result);
}
示例9: RedirectedError
public void RedirectedError()
{
int x =0;
var o = new Option((int y)=>x=y,"somevalue","description");
StringBuilder errOut = new StringBuilder();
using(var errStream = new StringWriter(errOut))
{
o.Invoke("","Nope this is wrong",errStream);
Assert.IsTrue(errOut.ToString().Contains("Nope this is wrong"));
}
}
示例10: Main
//this is the driver method that I am using to test the options class as it is being written, needs to be replaced with a good unit test suite
public static void Main (string[] args)
{
var opt = new Option(new []{"h","talk"},()=>Console.WriteLine("hello world"),"Prints greeting");
var opt2 = new Option(new []{"a","add3"},(int i)=>Console.WriteLine(i+3),"value","Adds 3 to value");
var opt3 = new Option(new []{"x","so","dsdsdsajdlasdsjkdjask","ThisIsAnotherOne","YetAnotherOne","ItGoesOn", "d"},()=>Console.WriteLine("Goodbye World"),"This is a test of word wrapping if everything goes ok this shoudl wrap around on to several lines while maintaining an offset for other text. If this is not wrapped correctly something is wrong...very wrong.");
Options opts = new Options("This is not the real options for this command so do not try them.")
{
opt,
opt2,
new Option((string x) => Console.WriteLine(x),"hostname","The hostname of the server"),
opt3,
};
opts.PrintUsage();
opt.Invoke("h",null);
opt2.Invoke("a","10000");
opts.Parse(new []{"--h","--add3","6"});
opts.Parse(new []{"-ha","7"});
opts.Parse(new []{"-a","this is fail"});
Console.ReadLine();
}