Refactor GetId method and update ICRUDService comments

Modified the `GetId<TId>` 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.
This commit is contained in:
Developer 02 2025-05-20 12:37:36 +02:00
parent dd679b79b4
commit 68d78afafe
2 changed files with 1 additions and 2 deletions

View File

@ -28,7 +28,7 @@ public static class EntityExtensions
/// <exception cref="InvalidOperationException"> /// <exception cref="InvalidOperationException">
/// Thrown if the object does not have a readable 'Id' property of type <typeparamref name="TId"/>. /// Thrown if the object does not have a readable 'Id' property of type <typeparamref name="TId"/>.
/// </exception> /// </exception>
public static TId? GetId<TId>(this object? obj) public static TId GetId<TId>(this object? obj)
=> obj.GetIdOrDefault<TId>() => obj.GetIdOrDefault<TId>()
?? throw new InvalidOperationException($"The object of type '{obj?.GetType().FullName ?? "null"}' does not have a readable 'Id' property of type '{typeof(TId).FullName}'."); ?? throw new InvalidOperationException($"The object of type '{obj?.GetType().FullName ?? "null"}' does not have a readable 'Id' property of type '{typeof(TId).FullName}'.");

View File

@ -14,7 +14,6 @@ namespace DigitalData.Core.Application.Interfaces
/// <returns>A task representing the asynchronous operation, with a <see cref="DataResult{TId}"/> containing the identifier of the created entity or an error message.</returns> /// <returns>A task representing the asynchronous operation, with a <see cref="DataResult{TId}"/> containing the identifier of the created entity or an error message.</returns>
Task<DataResult<TId>> CreateAsync(TCreateDto createDto); Task<DataResult<TId>> CreateAsync(TCreateDto createDto);
/// <summary> /// <summary>
/// Updates an existing entity based on the provided updateDTO and returns the result wrapped in an IServiceMessage, /// 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. /// indicating the success or failure of the operation, including the error messages on failure.