当前位置: 首页>>代码示例>>C#>>正文


C# Option.Invoke方法代码示例

本文整理汇总了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);
        }
开发者ID:digitalhermit,项目名称:Jmaxxz.Console,代码行数:8,代码来源:OptionTest.cs

示例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);
 }
开发者ID:digitalhermit,项目名称:Jmaxxz.Console,代码行数:8,代码来源:OptionTest.cs

示例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);
 }
开发者ID:digitalhermit,项目名称:Jmaxxz.Console,代码行数:8,代码来源:OptionTest.cs

示例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);
        }
开发者ID:digitalhermit,项目名称:Jmaxxz.Console,代码行数:8,代码来源:OptionTest.cs

示例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);
        }
开发者ID:digitalhermit,项目名称:Jmaxxz.Console,代码行数:8,代码来源:OptionTest.cs

示例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);
         }
开发者ID:digitalhermit,项目名称:Jmaxxz.Console,代码行数:8,代码来源:FlaglessOptionTest.cs

示例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);
            }
开发者ID:digitalhermit,项目名称:Jmaxxz.Console,代码行数:8,代码来源:FlaglessOptionTest.cs

示例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);
         }
开发者ID:digitalhermit,项目名称:Jmaxxz.Console,代码行数:8,代码来源:FlaglessOptionTest.cs

示例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"));
            }

        }
开发者ID:michaelgwelch,项目名称:Jmaxxz.Console,代码行数:12,代码来源:OptionRedirectedOutputTest.cs

示例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();
        }
开发者ID:digitalhermit,项目名称:Jmaxxz.Console,代码行数:22,代码来源:Main.cs


注:本文中的Option.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。