using System;
namespace Chernobyl
{
///
/// Instance that enables implicit conversion when using func extensions.
///
public struct Arg
{
///
public Arg(Func func)
{
Func = func;
}
///
/// Converts any instance to an .
///
public static implicit operator Arg(T value) => new Arg(() => value);
///
/// Converts a to an .
///
public static implicit operator Arg(Lazy lazy) => new Arg(() => lazy.Value);
///
/// Converts a value to an .
///
public static implicit operator Arg(Func func) => new Arg(func);
///
/// Returns the value of the argument.
///
public Func Func { get; }
}
///
/// Utility and extension methods for .
///
public static class Arg
{
///
/// Returns an that returns the default value of .
///
public static Arg Default() => new Arg(() => default);
// TODO: There appears to a bug where generic conversion sometimes does not work properly so
// we added the "AsArg" methods to get around this. Remove the "AsArg" methods once C#
// generic conversion bugs are fixed.
///
/// Converts any instance to an .
///
/// This method exists because C# support of generic implicit conversions doesn't
/// always work. Use this method if that is the case.
public static Arg AsArg(this T value) => value;
///
/// Converts to an .
///
/// This method exists because C# support of generic implicit conversions doesn't
/// always work. Use this method if that is the case.
public static Arg AsArg(this Lazy lazy) => lazy;
///
/// Converts a to an .
///
/// This method exists because C# support of generic implicit conversions doesn't
/// always work. Use this method if that is the case.
public static Arg AsArg(this Func func) => func;
}
}