Last active
September 28, 2022 02:47
-
-
Save poychang/6c1523dfb9dfd68937955f2a79634b5e to your computer and use it in GitHub Desktop.
[LINQ 擴充 - 然後呢] "然後呢"擴充方法 #C# #dotnet
This file contains hidden or 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
public static class ThenExtension | |
{ | |
/// <summary> | |
/// "然後呢"擴充方法 | |
/// </summary> | |
/// <typeparam name="T">原本的物件型別</typeparam> | |
/// <param name="instance">原本的物件</param> | |
/// <param name="fn">然後你要執行什麼,並回傳變更後的物件</param> | |
/// <returns>原本的物件,可能會變更原本物件的屬性值</returns> | |
public static T Then<T>(this T instance, Func<T, T> fn) => fn(instance); | |
/// <summary> | |
/// "然後呢"擴充方法 | |
/// </summary> | |
/// <typeparam name="TSource">原本的物件型別</typeparam> | |
/// <typeparam name="TResult">不同型別的物件</typeparam> | |
/// <param name="instance">原本的物件</param> | |
/// <param name="fn">然後你要執行什麼,並回傳變更後的物件</param> | |
/// <returns>不同型別的物件,和原本的物件型別不同</returns> | |
public static TResult Then<TSource, TResult>(this TSource instance, Func<TSource, TResult> fn) => fn(instance); | |
/// <summary> | |
/// "然後呢"擴充方法 | |
/// </summary> | |
/// <typeparam name="T">原本的物件型別</typeparam> | |
/// <param name="instance">原本的物件</param> | |
/// <param name="fn">然後你要執行什麼</param> | |
/// <returns>原本的物件,不會變更任何屬性值</returns> | |
public static T Then<T>(this T instance, Action<T> fn) { fn(instance); return instance; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment