/
krasninja
/
querycat
Обзор
Документация
Войти
/
krasninja
/
querycat
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/QueryCat.Backend/Functions/Aggregate/AggregateFunctionsUtils.cs
41 строка
1 KB
Ivan Kozhin
Move ErrorCode to Core namespace
28 дек 2023, 07:18
28 дек 2023, 07:18
035fe6b
Код
Авторство
О чём код?
using System.Runtime.CompilerServices; using QueryCat.Backend.Core; using QueryCat.Backend.Core.Types; namespace QueryCat.Backend.Functions.Aggregate; /// <summary> /// Utilities for aggregate functions. /// </summary> internal static class AggregateFunctionsUtils { /// <summary> /// The method applies following logic: /// 1. If next value is null - return. /// 2. If state is null - set it to the next value. /// 3. If state is not null - apply delegate. /// </summary> /// <param name="state">Initial state.</param> /// <param name="value">New value.</param> /// <param name="func">Delegate to invoke.</param> [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] internal static void ExecuteWithNullInitialState(ref VariantValue state, in VariantValue value, VariantValue.OperationBinaryDelegate func) { if (!value.IsNull) { if (state.IsNull) { state = value; } else { var newState = func.Invoke(in state, in value, out var errorCode); if (errorCode == ErrorCode.OK) { state = newState; } } } } }