using System;
using System.Linq.Expressions;
namespace Developpez.Dotnet
{
///
/// Fournit des opérateurs arithmétiques génériques.
///
public static partial class GenericOperators
{
///
/// Calcule la somme de deux valeurs
///
/// Premier opérande
/// Premier opérande
/// La somme des deux valeurs
public static T Add(T x, T y)
{
return OperatorCache.AddOperator(x, y);
}
///
/// Calcule la différence de deux valeurs
///
/// Premier opérande
/// Premier opérande
/// La différence entre les deux valeurs
public static T Subtract(T x, T y)
{
return OperatorCache.SubtractOperator(x, y);
}
///
/// Calcule le produit de deux valeurs
///
/// Premier opérande
/// Premier opérande
/// Le produit des deux valeurs
public static T Multiply(T x, T y)
{
return OperatorCache.MultiplyOperator(x, y);
}
///
/// Calcule le quotient de deux valeurs
///
/// Premier opérande
/// Premier opérande
/// Le quotient des deux valeurs
public static T Divide(T x, T y)
{
return OperatorCache.DivideOperator(x, y);
}
///
/// Calcule le reste de la division entre deux valeurs
///
/// Premier opérande
/// Premier opérande
/// Le reste de la division de x par y
public static T Modulo(T x, T y)
{
return OperatorCache.ModuloOperator(x, y);
}
private static class OperatorCache
{
public static readonly Func AddOperator = MakeBinaryOperator(ExpressionType.Add);
public static readonly Func SubtractOperator = MakeBinaryOperator(ExpressionType.Subtract);
public static readonly Func MultiplyOperator = MakeBinaryOperator(ExpressionType.Multiply);
public static readonly Func DivideOperator = MakeBinaryOperator(ExpressionType.Divide);
public static readonly Func ModuloOperator = MakeBinaryOperator(ExpressionType.Modulo);
}
}
}