What is the best or most interesting use of Extension Methods you’ve seen? [closed]
This is one that’s been getting some play from me lately: public static IDisposable Tag(this HtmlHelper html, string tagName) { if (html == null) throw new ArgumentNullException(“html”); Action<string> a = tag => html.Write(String.Format(tag, tagName)); a(“<{0}>”); return new Memento(() => a(“</{0}>”)); } Used like: using (Html.Tag(“ul”)) { this.Model.ForEach(item => using(Html.Tag(“li”)) Html.Write(item)); using(Html.Tag(“li”)) Html.Write(“new”); } Memento is … Read more