public Aggregate ( int records, AggregateType kind ) : object | ||
records | int | |
kind | AggregateType | |
Результат | object |
public override object Aggregate(int[] records, AggregateType kind)
{
bool hasData = false;
try
{
switch (kind)
{
case AggregateType.Min:
DateTimeOffset min = DateTimeOffset.MaxValue;
for (int i = 0; i < records.Length; i++)
{
int record = records[i];
if (HasValue(record))
{
min = (DateTimeOffset.Compare(_values[record], min) < 0) ? _values[record] : min;
hasData = true;
}
}
if (hasData)
{
return min;
}
return _nullValue;
case AggregateType.Max:
DateTimeOffset max = DateTimeOffset.MinValue;
for (int i = 0; i < records.Length; i++)
{
int record = records[i];
if (HasValue(record))
{
max = (DateTimeOffset.Compare(_values[record], max) >= 0) ? _values[record] : max;
hasData = true;
}
}
if (hasData)
{
return max;
}
return _nullValue;
case AggregateType.First:
if (records.Length > 0)
{
return _values[records[0]];
}
return null;
case AggregateType.Count:
int count = 0;
for (int i = 0; i < records.Length; i++)
{
if (HasValue(records[i]))
{
count++;
}
}
return count;
}
}
catch (OverflowException)
{
throw ExprException.Overflow(typeof(DateTimeOffset));
}
throw ExceptionBuilder.AggregateException(kind, _dataType);
}