More fluent C# / .NET

后端 未结 21 1292
名媛妹妹
名媛妹妹 2020-12-23 22:51

A co-worker of mine came up with this and I wonder what others think? Personally, I find it interesting but wonder if it is too big a departure? Code examples below. Extensi

21条回答
  •  执念已碎
    2020-12-23 23:53

    One more vote for "not useful". The With extension method doesn't do anything except wrap up sequenced statements with a method. C# already already has a built-in function for sequencing statements, its called ;.

    Similarly, the WithIf wraps an if-statement without any modification to the control flow. From my point of view, you're only inviting yourself to methods like:

    public static T For(
        this T t, int start, Func cond, Action f)
    {
        for(int i = start; cond(i); i++)
        {
            f(t, i);
        }
        return t;
    }
    

提交回复
热议问题