1212/// </summary>
1313public class OperationResult
1414{
15- private readonly List < OperationError > _errors = new ( ) ;
15+ private readonly List < IOperationError > _errors = new ( ) ;
1616 private readonly List < string > _successMessages = new ( ) ;
1717
1818 private readonly ILogger ? _logger ;
@@ -41,7 +41,7 @@ public IEnumerable<string> SuccessMessages
4141 /// <summary>
4242 /// Gets an <see cref="List{T}"/> containing the error codes and messages of the <see cref="OperationResult{T}" />.
4343 /// </summary>
44- public IReadOnlyCollection < OperationError > Errors => this . _errors . AsReadOnly ( ) ;
44+ public IReadOnlyCollection < IOperationError > Errors => this . _errors . AsReadOnly ( ) ;
4545
4646 /// <summary>
4747 /// Gets or sets the first exception that resulted from the operation.
@@ -97,7 +97,7 @@ public OperationResult AppendErrors(OperationResult otherOperationResult)
9797 }
9898
9999 /// <summary>
100- /// This method will append an error with a specific `user-friendly` message to this operation result instance.
100+ /// This method will append an <see cref="OperationError"/> error with a specific `user-friendly` message to this operation result instance.
101101 /// </summary>
102102 /// <param name="message">A label consuming component defining the 'user-friendly' message.</param>
103103 /// <param name="code">The unique code of the error.</param>
@@ -115,12 +115,32 @@ public OperationResult AppendError(string message, int? code = null, LogLevel? l
115115 }
116116
117117 /// <summary>
118- /// Appends an <see cref="OperationError"/> to the internal errors collection.
118+ /// This method will append an <typeparamref name="T"/> error with a specific `user-friendly` message to this operation result instance.
119+ /// </summary>
120+ /// <param name="message">A label consuming component defining the 'user-friendly' message.</param>
121+ /// <param name="code">The unique code of the error.</param>
122+ /// <param name="logLevel">The logging severity.</param>
123+ /// <param name="details">A <see cref="string"/> with error details.</param>
124+ /// <typeparam name="T">The type of <see cref="IOperationError"/> to append.</typeparam>
125+ /// <returns>The current instance of the <see cref="OperationResult"/>.</returns>
126+ public OperationResult AppendError < T > ( string message , int ? code = null , LogLevel ? logLevel = null , string ? details = null )
127+ where T : IOperationError , new ( )
128+ {
129+ if ( string . IsNullOrWhiteSpace ( message ) ) throw new ArgumentNullException ( nameof ( message ) ) ;
130+
131+ var error = new T ( ) { Message = message , Code = code , Details = details } ;
132+ this . AppendError ( error , logLevel ) ;
133+
134+ return this ;
135+ }
136+
137+ /// <summary>
138+ /// Appends an <see cref="IOperationError"/> to the internal errors collection.
119139 /// </summary>
120- /// <param name="error">An instance of <see cref="OperationError "/> to add to the internal errors collection.</param>
140+ /// <param name="error">An instance of <see cref="IOperationError "/> to add to the internal errors collection.</param>
121141 /// <param name="logLevel">The logging level.</param>
122142 /// <returns>The current instance of the <see cref="OperationResult"/>.</returns>
123- public OperationResult AppendError ( OperationError error , LogLevel ? logLevel = LogLevel . Error )
143+ public OperationResult AppendError ( IOperationError error , LogLevel ? logLevel = LogLevel . Error )
124144 {
125145 this . AppendErrorInternal ( error ) ;
126146
@@ -191,10 +211,10 @@ public static OperationResult FromError(string message, int? code = null, LogLev
191211 private static LogLevel GetLogLevel ( LogLevel ? optionalLevel ) => optionalLevel ?? LogLevel . Error ;
192212
193213 /// <summary>
194- /// Appends an <see cref="OperationError "/> to the internal errors collection.
214+ /// Appends an <see cref="IOperationError "/> to the internal errors collection.
195215 /// </summary>
196- /// <param name="error">An instance of <see cref="OperationError "/> to add to the internal errors collection.</param>
197- private void AppendErrorInternal ( OperationError error ) => this . _errors . Add ( error ) ;
216+ /// <param name="error">An instance of <see cref="IOperationError "/> to add to the internal errors collection.</param>
217+ private void AppendErrorInternal ( IOperationError error ) => this . _errors . Add ( error ) ;
198218}
199219
200220/// <summary>
0 commit comments