Hi Guys..
I have this two objects
class RNB
{
public RNB(double roomRate, double roomDays)
{
RoomRate = roomRate;
RoomDays = roomDays;
}
public double RoomRate { get; set; }
public double RoomDays { get; set; }
public const double BasicLimit = 100;
}
class HMS
{
public double Amount { get; set; }
public const double BasicLimit = 200;
}
And then I have this method:
public static double ComputeBasicAmount(double basicLimit, Func<double> multiplier)
{
return basicLimit * multiplier();
}
Sample usage:
static void Main(string[] args)
{
RNB rnb = new RNB(100, 2);
double result = ComputeBasicAmount(RNB.BasicLimit, () => rnb.RoomDays * rnb.RoomRate);
Console.WriteLine("RNB Basic Amt: " + result.ToString());
HMS hms = new HMS() { Amount = 1000 };
result = ComputeBasicAmount(HMS.BasicLimit, () => hms.Amount);
Console.WriteLine("HMS Basic Amt: " + result.ToString());
Console.Read();
}
The problem here, I Want to eliminate the passing of the BasicLimit because i think it looks redundant here. Is it possible to put the BasicLimit inside the ComputeBasicAmount method
Something like this..
public static double ComputeBasicAmount<T>(Func<T, double> multiplier, T obj)
{
return obj.BasicLimit * multiplier();
}
Thanks in advance guys...
PS: The basicLimit doesn't have to be CONST