本文整理汇总了C#中Func.ToResultFunc方法的典型用法代码示例。如果您正苦于以下问题:C# Func.ToResultFunc方法的具体用法?C# Func.ToResultFunc怎么用?C# Func.ToResultFunc使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Func
的用法示例。
在下文中一共展示了Func.ToResultFunc方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToResultFunc
public void ToResultFunc()
{
var f1_0 = new Func<string>(() => "");
var g1_0 = f1_0.ToResultFunc();
Assert.That(g1_0(), Is.EqualTo(Result.NewSuccess<string, Exception>("")));
f1_0 = new Func<string>(() => { throw new MyException(); });
g1_0 = f1_0.ToResultFunc();
Assert.That(g1_0(), Is.EqualTo(Result.NewFailure<string, Exception>(new MyException())));
f1_0 = new Func<string>(() => null);
g1_0 = f1_0.ToResultFunc();
Assert.That(g1_0(), Is.EqualTo(Result.NewFailure<string, Exception>(new NullResultException())));
var f2_0 = new Func<int?>(() => + 0);
var g2_0 = f2_0.ToResultFunc();
Assert.That(g2_0(), Is.EqualTo(Result.NewSuccess<int, Exception>( + 0)));
f2_0 = new Func<int?>(() => { throw new MyException(); });
g2_0 = f2_0.ToResultFunc();
Assert.That(g2_0(), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));
f2_0 = new Func<int?>(() => null);
g2_0 = f2_0.ToResultFunc();
Assert.That(g2_0(), Is.EqualTo(Result.NewFailure<int, Exception>(new NullResultException())));
var f1_1 = new Func<string, string>((a1) => a1);
var g1_1 = f1_1.ToResultFunc();
Assert.That(g1_1("1"), Is.EqualTo(Result.NewSuccess<string, Exception>("1")));
f1_1 = new Func<string, string>((a1) => { throw new MyException(); });
g1_1 = f1_1.ToResultFunc();
Assert.That(g1_1("1"), Is.EqualTo(Result.NewFailure<string, Exception>(new MyException())));
f1_1 = new Func<string, string>((a1) => null);
g1_1 = f1_1.ToResultFunc();
Assert.That(g1_1("1"), Is.EqualTo(Result.NewFailure<string, Exception>(new NullResultException())));
var f2_1 = new Func<int?, int?>((a1) => a1 + 0);
var g2_1 = f2_1.ToResultFunc();
Assert.That(g2_1(1), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 0)));
f2_1 = new Func<int?, int?>((a1) => { throw new MyException(); });
g2_1 = f2_1.ToResultFunc();
Assert.That(g2_1(1), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));
f2_1 = new Func<int?, int?>((a1) => null);
g2_1 = f2_1.ToResultFunc();
Assert.That(g2_1(1), Is.EqualTo(Result.NewFailure<int, Exception>(new NullResultException())));
var f1_2 = new Func<string, string, string>((a1, a2) => a1 + a2);
var g1_2 = f1_2.ToResultFunc();
Assert.That(g1_2("1", "2"), Is.EqualTo(Result.NewSuccess<string, Exception>("12")));
f1_2 = new Func<string, string, string>((a1, a2) => { throw new MyException(); });
g1_2 = f1_2.ToResultFunc();
Assert.That(g1_2("1", "2"), Is.EqualTo(Result.NewFailure<string, Exception>(new MyException())));
f1_2 = new Func<string, string, string>((a1, a2) => null);
g1_2 = f1_2.ToResultFunc();
Assert.That(g1_2("1", "2"), Is.EqualTo(Result.NewFailure<string, Exception>(new NullResultException())));
var f2_2 = new Func<int?, int?, int?>((a1, a2) => a1 + a2 + 0);
var g2_2 = f2_2.ToResultFunc();
Assert.That(g2_2(1, 2), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 0)));
f2_2 = new Func<int?, int?, int?>((a1, a2) => { throw new MyException(); });
g2_2 = f2_2.ToResultFunc();
Assert.That(g2_2(1, 2), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));
f2_2 = new Func<int?, int?, int?>((a1, a2) => null);
g2_2 = f2_2.ToResultFunc();
Assert.That(g2_2(1, 2), Is.EqualTo(Result.NewFailure<int, Exception>(new NullResultException())));
var f1_3 = new Func<string, string, string, string>((a1, a2, a3) => a1 + a2 + a3);
var g1_3 = f1_3.ToResultFunc();
Assert.That(g1_3("1", "2", "3"), Is.EqualTo(Result.NewSuccess<string, Exception>("123")));
f1_3 = new Func<string, string, string, string>((a1, a2, a3) => { throw new MyException(); });
g1_3 = f1_3.ToResultFunc();
Assert.That(g1_3("1", "2", "3"), Is.EqualTo(Result.NewFailure<string, Exception>(new MyException())));
f1_3 = new Func<string, string, string, string>((a1, a2, a3) => null);
g1_3 = f1_3.ToResultFunc();
Assert.That(g1_3("1", "2", "3"), Is.EqualTo(Result.NewFailure<string, Exception>(new NullResultException())));
var f2_3 = new Func<int?, int?, int?, int?>((a1, a2, a3) => a1 + a2 + a3 + 0);
var g2_3 = f2_3.ToResultFunc();
Assert.That(g2_3(1, 2, 3), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 0)));
f2_3 = new Func<int?, int?, int?, int?>((a1, a2, a3) => { throw new MyException(); });
g2_3 = f2_3.ToResultFunc();
Assert.That(g2_3(1, 2, 3), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));
f2_3 = new Func<int?, int?, int?, int?>((a1, a2, a3) => null);
g2_3 = f2_3.ToResultFunc();
Assert.That(g2_3(1, 2, 3), Is.EqualTo(Result.NewFailure<int, Exception>(new NullResultException())));
var f1_4 = new Func<string, string, string, string, string>((a1, a2, a3, a4) => a1 + a2 + a3 + a4);
var g1_4 = f1_4.ToResultFunc();
Assert.That(g1_4("1", "2", "3", "4"), Is.EqualTo(Result.NewSuccess<string, Exception>("1234")));
f1_4 = new Func<string, string, string, string, string>((a1, a2, a3, a4) => { throw new MyException(); });
g1_4 = f1_4.ToResultFunc();
Assert.That(g1_4("1", "2", "3", "4"), Is.EqualTo(Result.NewFailure<string, Exception>(new MyException())));
f1_4 = new Func<string, string, string, string, string>((a1, a2, a3, a4) => null);
g1_4 = f1_4.ToResultFunc();
Assert.That(g1_4("1", "2", "3", "4"), Is.EqualTo(Result.NewFailure<string, Exception>(new NullResultException())));
var f2_4 = new Func<int?, int?, int?, int?, int?>((a1, a2, a3, a4) => a1 + a2 + a3 + a4 + 0);
var g2_4 = f2_4.ToResultFunc();
Assert.That(g2_4(1, 2, 3, 4), Is.EqualTo(Result.NewSuccess<int, Exception>(1 + 2 + 3 + 4 + 0)));
f2_4 = new Func<int?, int?, int?, int?, int?>((a1, a2, a3, a4) => { throw new MyException(); });
g2_4 = f2_4.ToResultFunc();
Assert.That(g2_4(1, 2, 3, 4), Is.EqualTo(Result.NewFailure<int, Exception>(new MyException())));
f2_4 = new Func<int?, int?, int?, int?, int?>((a1, a2, a3, a4) => null);
g2_4 = f2_4.ToResultFunc();
//.........这里部分代码省略.........