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


C# Union.Match方法代码示例

本文整理汇总了C#中Union.Match方法的典型用法代码示例。如果您正苦于以下问题:C# Union.Match方法的具体用法?C# Union.Match怎么用?C# Union.Match使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Union的用法示例。


在下文中一共展示了Union.Match方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UnionWithT4_UsesCase4MatchOverElse

 public void UnionWithT4_UsesCase4MatchOverElse()
 {
     var union = new Union<int, string, Colors, Animals>(Animals.Sheep);
     var result = 0;
     union.Match().Case4().Do(_ => result = 1).Else(_ => result = 3).Exec();
     AreEqual(1, result);
 }
开发者ID:chamook,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2T3T4BasicMatchElseExecTests.cs

示例2: UnionWithT3_UsesElseIfNoCase3Match

 public void UnionWithT3_UsesElseIfNoCase3Match()
 {
     var union = new Union<int, string, Colors, Animals>(Colors.Green);
     var result = union.Match<bool>()
                       .Case1().Do(x => false).Case2().Do(x => false).Case4().Do(false).Else(x => true).Result();
     IsTrue(result);
 }
开发者ID:martijnhoekstra,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2T3T4BasicMatchElseTests.cs

示例3: UnionWithT2_UsesCase2MatchOverElse

 public void UnionWithT2_UsesCase2MatchOverElse()
 {
     var union = new Union<int, string, Colors, Animals>("x");
     var result = 0;
     union.Match().Case2().Do(_ => result = 1).Else(_ => result = 2).Exec();
     AreEqual(1, result);
 }
开发者ID:chamook,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2T3T4BasicMatchElseExecTests.cs

示例4: YesNo123OrOtherIntMatcherExample

 public static string YesNo123OrOtherIntMatcherExample(Union<int, bool> value) => 
     value.Match<string>()
          .Case1().Of(1).Or(2).Or(3).Do(i => $"{i} in range 1-3")
          .Case1().Do(i => $"int={i}")
          .Case2().Of(true).Do("Yes")
          .Case2().Of(false).Do("No")
          .Result();
开发者ID:martijnhoekstra,项目名称:SuccincT,代码行数:7,代码来源:UnionMatcherExamples.cs

示例5: Main

        static void Main(string[] args)
        {
            string s = "123";
            int i;
            if (int.TryParse(s, out i))
            {
                Console.WriteLine("Parsed {0}", i);
            }
            else
            {
                Console.WriteLine("Unable to parse '{0}'", s);
            }

            s = "1234zr";
            s.ParseInt()
                .Match()
                .None()
                    .Do(() => Console.WriteLine($"Unable to parse '{s}'"))
                .Some()
                    .Do(value => Console.WriteLine($"Parsed {value}"))
                .Exec();

            var demoUnion = new Union<int, bool>(false);
            string matcherResult = demoUnion.Match<string>()
                 .Case1().Of(1).Or(2).Or(3).Do(ui => $"{ui} in range 1-3")
                 .Case1().Do(ui => $"int={ui}")
                 .Case2().Of(true).Do("Yes")
                 .Case2().Of(false).Do("No")
                 .Result();
            Console.WriteLine(matcherResult);
        }
开发者ID:vermluh,项目名称:cs,代码行数:31,代码来源:Program.cs

示例6: UnionWithT1_UsesCase1MatchOverElse

 public void UnionWithT1_UsesCase1MatchOverElse()
 {
     var union = new Union<int, string, Colors, Animals>(2);
     var result = 0;
     union.Match().Case1().Do(x => result = x).Else(_ => result = 1).Exec();
     AreEqual(2, result);
 }
开发者ID:chamook,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2T3T4BasicMatchElseExecTests.cs

示例7: UnionWithT2_CaseOfExpressionSupported

 public void UnionWithT2_CaseOfExpressionSupported()
 {
     var union = new Union<int, string, Colors, Animals>("1");
     var result = union.Match<int>()
                       .Case1().Do(0).Case2().Of("1").Do(2).Case2().Do(1).Case3().Do(3).Case4().Do(4).Result();
     AreEqual(2, result);
 }
开发者ID:chamook,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2T3T4BasicMatchTests.cs

示例8: UnionWithT1_MatchesBasicCase1CorrectlyWithExec

 public void UnionWithT1_MatchesBasicCase1CorrectlyWithExec()
 {
     var union = new Union<int, string>(2);
     var result = 0;
     union.Match().Case1().Do(x => result = x).Case2().Do(x => result = 3).Exec();
     AreEqual(2, result);
 }
开发者ID:martijnhoekstra,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2Tests.cs

示例9: UnionWithT1_UsesElseIfNoCase1MatchWithExec

 public void UnionWithT1_UsesElseIfNoCase1MatchWithExec()
 {
     var union = new Union<int, string, Colors>(11);
     var result = 0;
     union.Match().Case2().Do(x => result = 1).Case3().Do(x => result = 3).Else(x => result = x.Case1).Exec();
     AreEqual(11, result);
 }
开发者ID:martijnhoekstra,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2T3BasicMatchExecTests.cs

示例10: UnionWithT2_UsesElseIfNoCase2MatchWithExec

 public void UnionWithT2_UsesElseIfNoCase2MatchWithExec()
 {
     var union = new Union<int, string, Colors>("fred");
     var result = 0;
     union.Match().Case1().Do(x => result = 1).Case3().Do(x => result = 3).Else(x => result = 2).Exec();
     AreEqual(2, result);
 }
开发者ID:martijnhoekstra,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2T3BasicMatchExecTests.cs

示例11: UnionWithT4_UsesElseExpressionIfNoCase3Match

 public void UnionWithT4_UsesElseExpressionIfNoCase3Match()
 {
     var union = new Union<int, string, Colors, Animals>(Animals.Cow);
     var result = union.Match<bool>()
                       .Case1().Do(x => false).Case2().Do(x => false).Case3().Do(false).Else(true).Result();
     IsTrue(result);
 }
开发者ID:martijnhoekstra,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2T3T4BasicMatchElseTests.cs

示例12: UnionWithT3_UsesCase3MatchOverElse

 public void UnionWithT3_UsesCase3MatchOverElse()
 {
     var union = new Union<int, string, Colors, Animals>(Colors.Blue);
     var result = 0;
     union.Match().Case3().Do(_ => result = 1).Else(_ => result = 3).Exec();
     AreEqual(1, result);
 }
开发者ID:chamook,项目名称:SuccincT,代码行数:7,代码来源:UnionT1T2T3T4BasicMatchElseExecTests.cs

示例13: UnionWithT4_UsesElseIfNoCase4Match

 public void UnionWithT4_UsesElseIfNoCase4Match()
 {
     var union = new Union<int, string, Colors, Animals>(Animals.Dog);
     var result = false;
     union.Match().Case1().Do(_ => result = false).Case2().Do(_ => result = false)
                  .Case3().Do(_ => result = false).Else(_ => result = true).Exec();
     IsTrue(result);
 }
开发者ID:chamook,项目名称:SuccincT,代码行数:8,代码来源:UnionT1T2T3T4BasicMatchElseExecTests.cs

示例14: UnionWithT1_CaseWhereExpressionSupported

 public void UnionWithT1_CaseWhereExpressionSupported()
 {
     var union = new Union<int, string, Colors, Animals>(3);
     var result = union.Match<int>()
                       .Case1().Of(2).Do(0).Case1().Where(x => x == 3).Do(1)
                       .Case2().Do(2).Case3().Do(3).Case4().Do(4).Result();
     AreEqual(1, result);
 }
开发者ID:chamook,项目名称:SuccincT,代码行数:8,代码来源:UnionT1T2T3T4BasicMatchTests.cs

示例15: UnionAActionA

 public void UnionAActionA()
 {
     const int val = 111;
     Union<int> union = new Union<int>(val);
     union.Match(
         (int i) => Assert.AreEqual(val, i)
     );
 }
开发者ID:TMVector,项目名称:DiscriminatedUnion,代码行数:8,代码来源:UnionMatchActionTests.cs


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