Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,34 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="CommunityToolkit.Diagnostics" Version="8.4.0" />
<PackageVersion Include="BenchmarkDotNet" Version="0.13.9" />
<PackageVersion Include="BenchmarkDotNet" Version="0.15.7" />
<PackageVersion Include="GitVersion.MsBuild" Version="6.1.0" />
<PackageVersion Include="JetBrains.Annotations" Version="2025.1.0-eap1" />
<PackageVersion Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageVersion Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Routing" Version="2.2.2" />
<PackageVersion Include="Microsoft.AspNetCore.Authorization" Version="9.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Authorization" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.2.0" />
<PackageVersion Include="Microsoft.AspNetCore.Razor" Version="2.2.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.0-preview.6.24327.7" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="9.0.2" />
<PackageVersion Include="System.Text.Encodings.Web" Version="9.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="9.0.2" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.2" />
<PackageVersion Include="System.Text.Json" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components" Version="9.0.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Caching.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.Json" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="10.0.0" />
<PackageVersion Include="System.Text.Encodings.Web" Version="10.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="10.0.0" />
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="10.0.0" />
<PackageVersion Include="System.Text.Json" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components" Version="10.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.Web" Version="10.0.0" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="9.0.2" />
<PackageVersion Include="Microsoft.Extensions.Caching.Memory" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.0" />
<PackageVersion Include="Microsoft.Extensions.Logging.Console" Version="10.0.0" />
</ItemGroup>
<ItemGroup>
<PackageVersion Include="StyleCop.Analyzers" Version="1.2.0-beta.556">
Expand All @@ -56,11 +56,11 @@
</PackageVersion>
</ItemGroup>
<ItemGroup>
<PackageVersion Include="DefaultDocumentation" Version="1.0.0-beta04">
<PackageVersion Include="DefaultDocumentation" Version="1.2.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
<PackageVersion Include="DefaultDocumentation.Markdown" Version="0.8.3-beta1">
<PackageVersion Include="DefaultDocumentation.Markdown" Version="1.2.2">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="BenchmarkDotNet" />
<PackageReference Include="BenchmarkDotNet.Diagnostics.Windows" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" VersionOverride="10.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Ustilz.Api.Data/Ustilz.Api.Data.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,24 @@ namespace Ustilz.Api.ApiResponse.Extensions;
/// </summary>
public static class RouteHandlerBuilderExtensions
{
/// <summary>
/// Method which add metadata : Produces <see cref="ApiResponseBody{TResponse}" />.
/// </summary>
/// <typeparam name="TResult">Response type.</typeparam>
/// <param name="routeHandlerBuilder">The route builder.</param>
/// <returns>Return the route builder.</returns>
public static RouteHandlerBuilder ProducesApiResponse<TResult>(this RouteHandlerBuilder routeHandlerBuilder)
=> routeHandlerBuilder.Produces<ApiResponseBody<TResult>>();
extension(RouteHandlerBuilder routeHandlerBuilder)
{
/// <summary>
/// Method which add metadata : Produces <see cref="ApiResponseBody{TResponse}" />.
/// </summary>
/// <typeparam name="TResult">Response type.</typeparam>
/// <returns>Return the route builder.</returns>
public RouteHandlerBuilder ProducesApiResponse<TResult>()
=> routeHandlerBuilder.Produces<ApiResponseBody<TResult>>();
}

/// <summary>
/// Method which add metadata : Produces <see cref="ApiResponseBody{TResponse}" />.
/// </summary>
/// <param name="routeHandlerBuilder">The route builder.</param>
/// <param name="statusCode">The status code.</param>
/// <returns>Return the route builder.</returns>
public static RouteHandlerBuilder ProducesApiResponse<TResult>(this RouteHandlerBuilder routeHandlerBuilder, HttpStatusCode statusCode)
=> routeHandlerBuilder.Produces<ApiResponseBody<TResult>>((int)statusCode);
extension(RouteHandlerBuilder routeHandlerBuilder, HttpStatusCode statusCode)
{
/// <summary>
/// Method which add metadata : Produces <see cref="ApiResponseBody{TResponse}" />.
/// </summary>
/// <returns>Return the route builder.</returns>
public RouteHandlerBuilder ProducesApiResponse<TResult>()
=> routeHandlerBuilder.Produces<ApiResponseBody<TResult>>((int)statusCode);
}
}
2 changes: 1 addition & 1 deletion src/Ustilz.Api/Ustilz.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
4 changes: 2 additions & 2 deletions src/Ustilz.AspNetCore.Mvc/Ustilz.AspNetCore.Mvc.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -23,7 +23,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release</OutputPath>
<DocumentationFile>bin\Release\net6.0\Ustilz.AspNetCore.Mvc.xml</DocumentationFile>
<DocumentationFile>bin\Release\net10.0\Ustilz.AspNetCore.Mvc.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
Expand Down
6 changes: 3 additions & 3 deletions src/Ustilz.AspNetCore/Ustilz.AspNetCore.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down Expand Up @@ -45,11 +45,11 @@
</PackageReference>
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DocumentationFile>bin\Debug\net6.0\Ustilz.AspNetCore.xml</DocumentationFile>
<DocumentationFile>bin\Debug\net10.0\Ustilz.AspNetCore.xml</DocumentationFile>
<OutputPath>bin\Debug</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release</OutputPath>
<DocumentationFile>bin\Release\net6.0\Ustilz.AspNetCore.xml</DocumentationFile>
<DocumentationFile>bin\Release\net10.0\Ustilz.AspNetCore.xml</DocumentationFile>
</PropertyGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Ustilz.Attributes/Ustilz.Attributes.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -20,7 +20,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release</OutputPath>
<DocumentationFile>bin\Release\net6.0\Ustilz.Attributes.xml</DocumentationFile>
<DocumentationFile>bin\Release\net10.0\Ustilz.Attributes.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
Expand Down
10 changes: 4 additions & 6 deletions src/Ustilz.Data/Extensions/QueryableExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,25 @@ public static IQueryable<T> TagWithDebugInfo<T>(
}

/// <summary>
/// Paginate a queryable.
/// ToPageable a queryable.
/// </summary>
/// <typeparam name="T">The type of the elements of <paramref name="queryable" />.</typeparam>
/// <param name="queryable">The queryable to paginate.</param>
/// <param name="page">The page number to return. Page numbers are 1-based, so the first page is page 1.</param>
/// <param name="pageSize">The size of the page to return. Must be greater than 0.</param>
/// <param name="orderBy">A function to order elements of the queryable. The function must return an <see cref="IOrderedQueryable{T}" />.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param>
/// <returns>A <see cref="PageableResult{T}" /> that contains the elements of the current page and the total number of elements.</returns>
public static async Task<PageableResult<T>> PaginateAsync<T>(
public static PageableResult<T> ToPageable<T>(
this IQueryable<T> queryable,
int page,
int pageSize,
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy,
CancellationToken cancellationToken = default)
Func<IQueryable<T>, IOrderedQueryable<T>> orderBy)
{
Guard.IsGreaterThan(page, 1);
Guard.IsGreaterThan(pageSize, 0);

queryable = orderBy(queryable);
var items = await queryable.Skip((page - 1) * pageSize).Take(pageSize).ToListAsync(cancellationToken).ConfigureAwait(false);
var items = queryable.Skip((page - 1) * pageSize).Take(pageSize).ToList();
var totalElements = queryable.Count();
return new(items, totalElements);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Ustilz.Data/Ustilz.Data.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -21,7 +21,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>bin\Release\net6.0\Ustilz.Data.xml</DocumentationFile>
<DocumentationFile>bin\Release\net10.0\Ustilz.Data.xml</DocumentationFile>
<DefineConstants>JETBRAINS_ANNOTATIONS</DefineConstants>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ namespace Ustilz.Extensions.Configuration;
[PublicAPI]
public static class ExtensionsConfigurationBuilder
{
/// <summary>The use app settings json.</summary>
/// <param name="builder">The builder.</param>
/// <exception cref="ArgumentNullException">Lève une exception lorsque la variable d'environnement ASPNETCORE_ENVIRONMENT n'est pas trouvée.</exception>
/// <returns>The <see cref="IConfigurationBuilder" />.</returns>
/// <exception cref="ArgumentException">path1, path2, or path3 contains one or more of the invalid characters defined in <see cref="System.IO.Path.GetInvalidPathChars"></see>.</exception>
public static IConfigurationBuilder UseAppSettingsJson(this IConfigurationBuilder builder)
extension(IConfigurationBuilder builder)
{
// Set up configuration sources.
builder.AddJsonFile("appsettings.json", true);
builder.AddJsonFile(
Path.Combine(
AppContext.BaseDirectory,
$"..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}",
"appsettings.Development.json"),
true);
/// <summary>The use app settings json.</summary>
/// <exception cref="ArgumentNullException">Lève une exception lorsque la variable d'environnement ASPNETCORE_ENVIRONMENT n'est pas trouvée.</exception>
/// <returns>The <see cref="IConfigurationBuilder" />.</returns>
/// <exception cref="ArgumentException">path1, path2, or path3 contains one or more of the invalid characters defined in <see cref="System.IO.Path.GetInvalidPathChars"></see>.</exception>
public IConfigurationBuilder UseAppSettingsJson()
{
// Set up configuration sources.
builder.AddJsonFile("appsettings.json", true);
builder.AddJsonFile(
Path.Combine(
AppContext.BaseDirectory,
$"..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}..{Path.DirectorySeparatorChar}",
"appsettings.Development.json"),
true);

return builder;
return builder;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>preview</LangVersion>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -20,7 +20,7 @@
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<OutputPath>bin\Release</OutputPath>
<DocumentationFile>bin\Release\net6.0\Ustilz.Extensions.Configuration.xml</DocumentationFile>
<DocumentationFile>bin\Release\net10.0\Ustilz.Extensions.Configuration.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\GlobalSuppressions.cs" Link="GlobalSuppressions.cs" />
Expand Down
45 changes: 25 additions & 20 deletions src/Ustilz.Extensions/Enumerables/EnumerableExtensions.byte.cs
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
namespace Ustilz.Extensions.Enumerables;

using System;

using Ustilz.Extensions.Strings;

/// <summary>The extensions i enumerable.</summary>
public static partial class EnumerableExtensions
{
/// <summary>
/// Converts bytes collection to hexadecimal representation.
/// </summary>
/// <param name="bytes">Bytes to convert.</param>
/// <returns>Hexadecimal representation string.</returns>
public static string ToHexString(this IEnumerable<byte> bytes)
extension(IEnumerable<byte> bytes)
{
ArgumentNullException.ThrowIfNull(bytes);
/// <summary>
/// Converts bytes collection to hexadecimal representation.
/// </summary>
/// <returns>Hexadecimal representation string.</returns>
public string ToHexString()
{
ArgumentNullException.ThrowIfNull(bytes);

return string.Join(string.Empty, bytes.Select(b => $"0{b:X}".Right(2)));
return string.Join(string.Empty, bytes.Select(b => $"0{b:X}".Right(2)));
}
}

/// <summary>
/// Converts a byte array to a base64 image.
/// </summary>
/// <param name="byteArrayIn">Byte array to convert.</param>
/// <param name="imageType">The image type.</param>
/// <returns>The base64 image.</returns>
/// <remarks>
/// This method takes a byte array and an image type as input, converts the byte array to a base64 string,
/// and then formats it as a data URL with the specified image type.
/// </remarks>
public static string ByteArrayToBase64Image(this byte[] byteArrayIn, string imageType)
=> $"data:image/{imageType};base64,{Convert.ToBase64String(byteArrayIn)}";
extension(byte[] byteArrayIn, string imageType)
{
/// <summary>
/// Converts a byte array to a base64 image.
/// </summary>
/// <returns>The base64 image.</returns>
/// <remarks>
/// This method takes a byte array and an image type as input, converts the byte array to a base64 string,
/// and then formats it as a data URL with the specified image type.
/// </remarks>
public string ByteArrayToBase64Image()
=> $"data:image/{imageType};base64,{Convert.ToBase64String(byteArrayIn)}";
}
}
Loading
Loading