public static object Sum(FunctionContext context, IEnumerable data, ExpressionNode node) { int count; StorageType type; return(Aggregates.Sum(data, node, context.GlobalContext, nameof(Sum), out count, out type)); }
private static object Mean( IEnumerable data, ExpressionNode node, object context, string exp, out int count, out StorageType type) { count = 0; type = StorageType.Empty; object obj = Aggregates.Sum(data, node, context, exp, out count, out type); if (count == 0) { return((object)0); } switch (type) { case StorageType.Char: return((object)((int)(char)obj / count)); case StorageType.SByte: case StorageType.Byte: case StorageType.Int16: case StorageType.UInt16: case StorageType.Int32: case StorageType.UInt32: return((object)(Convert.ToDouble(obj) / (double)count)); case StorageType.Int64: case StorageType.UInt64: return((object)(Convert.ToDecimal(obj) / (Decimal)count)); case StorageType.Single: return((object)(float)((double)(float)obj / (double)count)); case StorageType.Double: return((object)((double)obj / (double)count)); case StorageType.Decimal: case StorageType.String: return((object)((Decimal)obj / (Decimal)count)); case StorageType.TimeSpan: return((object)new TimeSpan(((TimeSpan)obj).Ticks / (long)count)); case StorageType.SqlByte: return((object)((SqlDouble)((SqlByte)obj) / (SqlDouble)((double)count))); case StorageType.SqlDecimal: return((object)((SqlDouble)((SqlDecimal)obj) / (SqlDouble)((double)count))); case StorageType.SqlDouble: return((object)((SqlDouble)obj / (SqlDouble)((double)count))); case StorageType.SqlInt16: return((object)((SqlDouble)((SqlInt16)obj) / (SqlDouble)((double)(short)count))); case StorageType.SqlInt32: return((object)((SqlDouble)((SqlInt32)obj) / (SqlDouble)((double)count))); case StorageType.SqlInt64: return((object)((SqlDouble)((SqlInt64)obj) / (SqlDouble)((double)count))); case StorageType.SqlMoney: return((object)((SqlMoney)obj / (SqlMoney)((long)count))); case StorageType.SqlSingle: return((object)((SqlSingle)obj / (SqlSingle)((float)count))); default: throw InvalidExpressionException.TypeMismatch(exp); } }