本文整理汇总了C#中Union类的典型用法代码示例。如果您正苦于以下问题:C# Union类的具体用法?C# Union怎么用?C# Union使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Union类属于命名空间,在下文中一共展示了Union类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例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);
}
示例3: 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();
示例4: DifferentT3Values_ArentEqual
public void DifferentT3Values_ArentEqual()
{
var a = new Union<int, string, Colors, Animals>(Colors.Blue);
var b = new Union<int, string, Colors, Animals>(Colors.Red);
IsFalse(a.Equals(b));
IsFalse(a == b);
}
示例5: 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);
}
示例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);
}
示例7: DifferentT3Values_ArentEqual
public void DifferentT3Values_ArentEqual()
{
var a = new Union<int, string, Colors>(Colors.Blue);
var b = new Union<int, string, Colors>(Colors.Green);
IsFalse(a.Equals(b));
IsTrue(a != b);
}
示例8: FontSize
public static ReactStyle FontSize(Union<string, int> fontSize)
{
return new ReactStyle
{
FontSize = fontSize
};
}
示例9: 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);
}
示例10: 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);
}
示例11: DifferentT2Values_ArentEqual
public void DifferentT2Values_ArentEqual()
{
var a = new Union<int, string, Colors>("abc");
var b = new Union<int, string, Colors>("def");
IsFalse(a.Equals(b));
IsTrue(a != b);
}
示例12: 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);
}
示例13: 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);
}
示例14: 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);
}
示例15: 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);
}