Skip to content

Commit 293e3aa

Browse files
committed
Atualização de versão e melhorias na estrutura SaveResult
* Atualização de versão - Atualizou a propriedade `ProbVer` para a nova versão `1.0.0-preview-4.4`. * Melhoria na estrutura SaveResult - Adicionou `using System.Diagnostics;` para funcionalidades adicionais. - Modificou o construtor para incluir uma propriedade `Exception`. - Introduziu uma nova propriedade `Exception` para armazenar exceções. - Adicionou o método `EnsureSuccess` para validação de resultados.
1 parent 4d928b5 commit 293e3aa

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

RoyalCode.EnterprisePatterns/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
</PropertyGroup>
2626
<PropertyGroup>
2727
<ValVer>1.0.0-preview-2.0</ValVer>
28-
<ProbVer>1.0.0-preview-4.3</ProbVer>
28+
<ProbVer>1.0.0-preview-4.4</ProbVer>
2929
<HintVer>1.0.0</HintVer>
3030
<SearchVer>0.8.1</SearchVer>
3131
</PropertyGroup>

RoyalCode.EnterprisePatterns/RoyalCode.UnitOfWork.Abstractions/SaveResult.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using RoyalCode.SmartProblems;
2+
using System.Diagnostics;
23
using System.Diagnostics.CodeAnalysis;
34
using System.Runtime.CompilerServices;
45

@@ -53,6 +54,7 @@ public SaveResult(int changes)
5354
public SaveResult(Exception ex)
5455
{
5556
Problems = Problems.InternalError(ex);
57+
Exception = ex;
5658
}
5759

5860
/// <summary>
@@ -65,6 +67,11 @@ public SaveResult(Exception ex)
6567
/// </summary>
6668
public Problems? Problems { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; }
6769

70+
/// <summary>
71+
/// The exception that occurred during the save operation, if any.
72+
/// </summary>
73+
public Exception? Exception { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; }
74+
6875
/// <summary>
6976
/// Returns true if the save operation succeeded.
7077
/// </summary>
@@ -112,6 +119,23 @@ public bool IsSuccessOrGetProblems([NotNullWhen(false)] out Problems? problems)
112119
return IsSuccess;
113120
}
114121

122+
/// <summary>
123+
/// Validates the result and throws an exception if it's a failure.
124+
/// </summary>
125+
/// <exception cref="InvalidOperationException">
126+
/// Thrown when the save operation failed, either due to an exception or problems.
127+
/// </exception>
128+
[StackTraceHidden]
129+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
130+
public void EnsureSuccess()
131+
{
132+
if (Exception is not null)
133+
throw new InvalidOperationException($"Save operation failed with exception: {Exception.Message}", Exception);
134+
135+
if (IsFailure)
136+
throw Problems.ToException("Save operation failed with problem(s):\n - {0}", "\n - ");
137+
}
138+
115139
/// <summary>
116140
/// Convert the save result to an operation result.
117141
/// </summary>

0 commit comments

Comments
 (0)