ExtensionMethod.NET Home of 876 C#, Visual Basic, F# and Javascript extension methods


Allows chaining together actions to be taken place on the fly. It works with any object. Its a simple concept but I couldn't find any examples that does the same.


public static T Chain<T>(this T source, Action<T> action)
    return source;


var l = new Collection<SelectListItem>{
 new SelectListItem{ Text="t0", Value="y0" },
 new SelectListItem{ Text="t1", Value="y1" },
 new SelectListItem{ Text="t2", Value="y2" },
 new SelectListItem{ Text="t2", Value="y3" },
}.Chain(o => o.ForEachYield(m => m.Selected = (m.Value == "y3")));

Author: Daniel Gidman

Submitted on: 30 nov 2010

Language: C#

Type: System.Variant

Views: 5509