feat: spec + repo
This commit is contained in:
parent
eff887b49f
commit
2206fe027a
78 changed files with 3870 additions and 0 deletions
|
|
@ -0,0 +1,80 @@
|
|||
// Copyright (c) The Geekeey Authors
|
||||
// SPDX-License-Identifier: EUPL-1.2
|
||||
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace Geekeey.Request.Persistence;
|
||||
|
||||
/// <summary>
|
||||
/// Provides extension methods for <see cref="OrderedSpecificationBuilder{T}"/>.
|
||||
/// </summary>
|
||||
public static class OrderedBuilderExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a ThenBy expression for secondary ordering.
|
||||
/// </summary>
|
||||
/// <param name="builder">The ordered builder.</param>
|
||||
/// <param name="expression">The expression.</param>
|
||||
/// <typeparam name="T">The entity type.</typeparam>
|
||||
/// <returns>The ordered builder.</returns>
|
||||
public static OrderedSpecificationBuilder<T> ThenBy<T>(this OrderedSpecificationBuilder<T> builder, Expression<Func<T, object?>> expression)
|
||||
{
|
||||
return ThenBy(builder, expression, condition: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a ThenBy expression when <paramref name="condition"/> is <see langword="true"/>.
|
||||
/// </summary>
|
||||
/// <param name="builder">The ordered builder.</param>
|
||||
/// <param name="expression">The expression.</param>
|
||||
/// <param name="condition">Whether to apply the ThenBy.</param>
|
||||
/// <typeparam name="T">The entity type.</typeparam>
|
||||
/// <returns>The ordered builder.</returns>
|
||||
public static OrderedSpecificationBuilder<T> ThenBy<T>(this OrderedSpecificationBuilder<T> builder, Expression<Func<T, object?>> expression, bool condition)
|
||||
{
|
||||
if (condition && !builder.IsChainDiscarded)
|
||||
{
|
||||
builder.Builder.OrderExpressions.Add(new OrderExpressionInfo<T>(expression, OrderType.ThenBy));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.IsChainDiscarded = true;
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a ThenByDescending expression for secondary ordering.
|
||||
/// </summary>
|
||||
/// <param name="builder">The ordered builder.</param>
|
||||
/// <param name="expression">The expression.</param>
|
||||
/// <typeparam name="T">The entity type.</typeparam>
|
||||
/// <returns>The ordered builder.</returns>
|
||||
public static OrderedSpecificationBuilder<T> ThenByDescending<T>(this OrderedSpecificationBuilder<T> builder, Expression<Func<T, object?>> expression)
|
||||
{
|
||||
return ThenByDescending(builder, expression, condition: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a ThenByDescending expression when <paramref name="condition"/> is <see langword="true"/>.
|
||||
/// </summary>
|
||||
/// <param name="builder">The ordered builder.</param>
|
||||
/// <param name="expression">The expression.</param>
|
||||
/// <param name="condition">Whether to apply the ThenByDescending.</param>
|
||||
/// <typeparam name="T">The entity type.</typeparam>
|
||||
/// <returns>The ordered builder.</returns>
|
||||
public static OrderedSpecificationBuilder<T> ThenByDescending<T>(this OrderedSpecificationBuilder<T> builder, Expression<Func<T, object?>> expression, bool condition)
|
||||
{
|
||||
if (condition && !builder.IsChainDiscarded)
|
||||
{
|
||||
builder.Builder.OrderExpressions.Add(new OrderExpressionInfo<T>(expression, OrderType.ThenByDescending));
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.IsChainDiscarded = true;
|
||||
}
|
||||
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue