Extension Method:
private static decimal GetDecimal(object value)
{
decimal result = 0;
decimal.TryParse(GetString(value), out result);
return result;
}
public static decimal GetDecimal(this decimal? value)
{
return GetDecimal(value);
}
public static decimal GetDecimal(this decimal value)
{
return GetDecimal(value);
}
public static string GetString(object value)
{
string result = "";
if (value != null && value != DBNull.Value)
result = value.ToString();
return result;
}
private static decimal GetDecimal(object value)
{
decimal result = 0;
decimal.TryParse(GetString(value), out result);
return result;
}
public static decimal GetDecimal(this decimal? value)
{
return GetDecimal(value);
}
public static decimal GetDecimal(this decimal value)
{
return GetDecimal(value);
}
public static string GetString(object value)
{
string result = "";
if (value != null && value != DBNull.Value)
result = value.ToString();
return result;
}
Please provide a way to invoke the two types of extension method with example
ReplyDeleteSample:
ReplyDeletedecimal result = db.Vouchers.Where(i=>i.SelectedCustomerID==23).Sum(i=>i.Amount).GetDecimal();