Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 76079ef

Browse files
committed
Add TypeConstants for ZeroTask/TrueTask/FalseTask/EmptyTask/EmptyObject
1 parent 3096a01 commit 76079ef

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/ServiceStack.Text/AutoMappingUtils.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public static T ConvertTo<T>(this object from)
4242
return to.PopulateWith(from);
4343
}
4444

45+
public static To ThenDo<To>(this To to, Action<To> fn)
46+
{
47+
fn(to);
48+
return to;
49+
}
50+
4551
public static object ConvertTo(this object from, Type type)
4652
{
4753
if (from == null)

src/ServiceStack.Text/TypeConstants.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
4+
using System.Threading.Tasks;
45

56
namespace ServiceStack.Text
67
{
78
public static class TypeConstants
89
{
10+
static TypeConstants()
11+
{
12+
ZeroTask = InTask(0);
13+
TrueTask = InTask(true);
14+
FalseTask = InTask(false);
15+
EmptyTask = InTask((object)null);
16+
}
17+
18+
private static Task<T> InTask<T>(this T result)
19+
{
20+
var tcs = new TaskCompletionSource<T>();
21+
tcs.SetResult(result);
22+
return tcs.Task;
23+
}
24+
25+
public static readonly Task<int> ZeroTask;
26+
public static readonly Task<bool> TrueTask;
27+
public static readonly Task<bool> FalseTask;
28+
public static readonly Task<object> EmptyTask;
29+
30+
public static readonly object EmptyObject = new object();
31+
932
public static readonly string[] EmptyStringArray = new string[0];
1033
public static readonly long[] EmptyLongArray = new long[0];
1134
public static readonly int[] EmptyIntArray = new int[0];

0 commit comments

Comments
 (0)