More fluent C# / .NET

后端 未结 21 1286
名媛妹妹
名媛妹妹 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:44

    They're just different coding styles, what do you mean by "too big a departure"? Departure from what? From what you're used to? Only you can decide that. I will say that VB's With block has done more harm than good to code readability, and I would not try to replicate the behavior in C#, but that's just my preference.

    I pretty much always use this for FindControl (yeah, strongly typed to RepeaterItem, it doesn't have to be, but that's the only thing I ever use it for anyway):

    public static T FindControl(this RepeaterItem item, string id) 
    {
        return item.FindControl(id) as T;
    }
    

    And invoke it like so:

    Literal myLiteral = e.Item.FindControl("myLiteral");
    

提交回复
热议问题