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
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;
}