From 68d78afafe2d27e80430e021c1c97ed3a32d8d24 Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Tue, 20 May 2025 12:37:36 +0200 Subject: [PATCH] Refactor GetId method and update ICRUDService comments Modified the `GetId` method in the `EntityExtensions` class to change its return type from nullable `TId?` to non-nullable `TId`, ensuring stricter type safety by throwing an `InvalidOperationException` when the `Id` property is not readable. Removed a summary comment in the `ICRUDService` interface related to the `CreateAsync` method, which may indicate ongoing documentation updates for clarity on the method's functionality and parameters. --- DigitalData.Core.Application/EntityExtensions.cs | 2 +- DigitalData.Core.Application/Interfaces/ICRUDService.cs | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/DigitalData.Core.Application/EntityExtensions.cs b/DigitalData.Core.Application/EntityExtensions.cs index 91b448c..99f779e 100644 --- a/DigitalData.Core.Application/EntityExtensions.cs +++ b/DigitalData.Core.Application/EntityExtensions.cs @@ -28,7 +28,7 @@ public static class EntityExtensions /// /// Thrown if the object does not have a readable 'Id' property of type . /// - public static TId? GetId(this object? obj) + public static TId GetId(this object? obj) => obj.GetIdOrDefault() ?? throw new InvalidOperationException($"The object of type '{obj?.GetType().FullName ?? "null"}' does not have a readable 'Id' property of type '{typeof(TId).FullName}'."); diff --git a/DigitalData.Core.Application/Interfaces/ICRUDService.cs b/DigitalData.Core.Application/Interfaces/ICRUDService.cs index 82f3bc8..eafcca1 100644 --- a/DigitalData.Core.Application/Interfaces/ICRUDService.cs +++ b/DigitalData.Core.Application/Interfaces/ICRUDService.cs @@ -14,7 +14,6 @@ namespace DigitalData.Core.Application.Interfaces /// A task representing the asynchronous operation, with a containing the identifier of the created entity or an error message. Task> CreateAsync(TCreateDto createDto); - /// /// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage, /// indicating the success or failure of the operation, including the error messages on failure.