using System;
using System.Collections.Generic;
using System.Reflection;
using Chernobyl.Attribution;
using Chernobyl.Reflection;
namespace Chernobyl.Extensions
{
///
/// Extensions and utility methods for .
///
public static class CallbackExtensions
{
///
/// Returns the as its
/// equivalent.
///
/// The type returned to the response channel.
/// The method to return as an .
/// as .
public static Action AsAction(this Callback callback)
{
return new Action(callback);
}
///
/// Returns the as its
/// equivalent.
///
/// The type returned to the response channel.
/// The method to return as an .
/// as .
public static Callback AsCallback(this Action action)
{
return new Callback(action);
}
///
/// Projects each element of a callback into a new form using the
/// specified selector.
///
/// The type of the callback origin.
/// The type of the callback destination.
/// The method to receive the result.
/// The method that will convert the source to
/// the result.
/// The method to receive the source.
public static Callback Select(
this Callback callback, Func selector)
{
return source =>
{
var result = selector(source);
callback(result);
};
}
}
}