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

Pipe

It is like pipe operator in F# and is useful for chaining function calls especially in expressions. (More in http://foop.codeplex.com/)

Source

public static R Pipe<T, R>(this T o, Func<T, R> func)
{
    if (func == null) throw new ArgumentNullException("func", "'func' can not be null.");
    T buffer = o;
    return func(buffer);
}
public static T Pipe<T>(this T o, Action<T> action)
{
    if (action == null) throw new ArgumentNullException("action", "'action' can not be null.");
    T buffer = o;
    action(buffer);
    return buffer;
}

Example

<%= variable.Pipe(x => this.Fun1(x)).Pipe(x =>
{
    ...;
    return this.F2(x);
}) %>

Author: Kaveh Shahbazian

Submitted on: 4 jan 2010

Language: C#

Type: System.Object

Views: 5479