Last active
January 14, 2022 08:48
-
-
Save in-async/813a7f0cb3407c09ba79e0e9ae479839 to your computer and use it in GitHub Desktop.
式ブロック的なヘルパー。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace Commons { | |
/// <remarks> | |
/// cf. Proposal: Expression blocks https://github.com/dotnet/csharplang/issues/3086 | |
/// cf. Proposal: Sequence Expressions https://github.com/dotnet/csharplang/issues/377 | |
/// </remarks> | |
public static class ExpressionFunc { | |
public static T With<T>(this T obj, Action<T> action) { | |
if (action is null) { throw new ArgumentNullException(nameof(action)); } | |
action(obj); | |
return obj; | |
} | |
public static TResult To<T, TResult>(this T obj, Func<T, TResult> func) { | |
if (func is null) { throw new ArgumentNullException(nameof(func)); } | |
return func(obj); | |
} | |
public static void With(Action action) { | |
if (action is null) { throw new ArgumentNullException(nameof(action)); } | |
action(); | |
} | |
public static TResult To<TResult>(Func<TResult> func) { | |
if (func is null) { throw new ArgumentNullException(nameof(func)); } | |
return func(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment