tags:

views:

160

answers:

0

Place the following in a core assembly:

public delegate TResult Func<TResult>();
public delegate TResult Func<T, TResult>(T arg1);
public delegate TResult Func<T1, T2, TResult>(T1 arg1, T2 arg2);
public delegate TResult Func<T1, T2, T3, TResult>(T1 arg1, T2 arg2, T3 arg3);
public delegate TResult Func<T1, T2, T3, T4, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);
public delegate TResult Func<T1, T2, T3, T4, T5, TResult>(T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5);

public delegate void Action<T>(T obj);
public delegate void Action<T1, T2>(T1 arg1, T2 arg2);
public delegate void Action<T1, T2, T3>(T1 arg1, T2 arg2, T3 arg3);
public delegate void Action<T1, T2, T3, T4>(T1 arg1, T2 arg2, T3 arg3, T4 arg4);

Next, use lambdas normally:

    using MyClassLibararyNamespace;

    public void RefreshControls()
    {
        Func<double, string> InchesToFormattedLength = (length) =>
            UnitsOfMeasure.ConvertValue(length, UnitOfMeasure.Inches, 
            UnitsOfMeasure.MeasurementSystem == MeasurementSystem.Imperial ? 
            UnitOfMeasure.Feet : UnitOfMeasure.Meters).ToString("0.00");

            ...

        textBoxWallHeight.Text = InchesToFormattedLength(this.ProjectSetup.WallHeight);
        textBoxTransverseWallLength.Text = InchesToFormattedLength(this.ProjectSetup.TransverseWallLength);
        textBoxRadialWallLength.Text = InchesToFormattedLength(this.ProjectSetup.RadialWallLength);

Also, .Net 3.5+ projects can benefit from this, as well, if additional parameters are required.