本文整理汇总了C#中Option.Match方法的典型用法代码示例。如果您正苦于以下问题:C# Option.Match方法的具体用法?C# Option.Match怎么用?C# Option.Match使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Option
的用法示例。
在下文中一共展示了Option.Match方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteErrorSpecificTypeInLambda
private static Option<Exception> WriteErrorSpecificTypeInLambda(Option<Exception> result)
{
result
.Match<C>((C item) => Console.WriteLine("C"))
.Match<B>((B item) => Console.WriteLine("B"))
.Match<A>((A item) => Console.WriteLine("A"));
return result;
}
示例2: WriteError
private static Option<Exception> WriteError(Option<Exception> result)
{
result
.Match<C>(item => Console.WriteLine("C"))
.Match<B>(item => Console.WriteLine("B"))
.Match<A>(item => Console.WriteLine("A"));
return result;
}
示例3: SinglePositiveOddDigitReporter
public static string SinglePositiveOddDigitReporter(Option<int> data) =>
data.Match<string>()
.Some().Of(0).Do(x => "0 isn't positive or negative")
.Some().Where(x => x == 1 || x == 3 || x == 5 || x == 7 || x == 9).Do(x => x.ToString())
.Some().Where(x => x > 9).Do(x => $"{x} isn't 1 digit")
.Some().Where(x => x < 0).Do(i => $"{i} isn't positive")
.Some().Do(x => $"{x} isn't odd")
.None().Do("There was no value")
.Result();
示例4: SinglePositiveOddDigitPrinter
public static void SinglePositiveOddDigitPrinter(Option<int> data) =>
data.Match()
.Some().Of(0).Do(x => WriteLine("0 isn't positive or negative"))
.Some().Where(x => x == 1 || x == 3 || x == 5 || x == 7 || x == 9).Do(WriteLine)
.Some().Where(x => x > 9).Do(i => WriteLine("{0} isn't 1 digit", i))
.Some().Where(x => x < 0).Do(i => WriteLine("{0} isn't positive", i))
.Some().Do(x => WriteLine("{0} isn't odd", x))
.Else(o => WriteLine("There was no value"))
.Exec();
示例5: NumberNamer
public static string NumberNamer(Option<int> data)
{
var names = new[] { "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" };
return data.Match<string>()
.Some().Where(i => i >= 1 && i <= 9).Do(i => names[i - 1])
.Some().Do(x => x.ToString())
.None().Do("None")
.Result();
}
示例6: PrintOption
public static void PrintOption(Option<int> data) =>
data.Match()
.Some().Do(WriteLine)
.None().Do(() => { })
.Exec();
示例7: OptionMatcher
public static void OptionMatcher(Option<int> data) =>
data.Match()
.Some().Of(1).Or(2).Or(3).Do(WriteLine)
.Some().Do(i => WriteLine("{0} isn't 1, 2 or 3!", i))
.None().Do(() => { })
.Exec();
示例8: Match_Mathed_Executed
public void Match_Mathed_Executed()
{
var option = new Option<int>(1);
var mock = new Mock<OptionTests>();
var result = option.Match(x => x == 1, mock.Object.OnMatch);
mock.Verify(x => x.OnMatch(option.Value), Times.Once);
Assert.Equal(1, result.Value);
}