@@ -44,7 +44,7 @@ public IEnumerable<string>? SuccessMessages
4444 /// Gets an <see cref="List{T}"/> containing the error codes and messages of the <see cref="OperationResult{T}" />.
4545 /// </summary>
4646 public List < IOperationError > Errors { get ; internal set ; } = new List < IOperationError > ( ) ;
47-
47+
4848 /// <summary>
4949 /// Gets or sets the first exception that resulted from the operation.
5050 /// </summary>
@@ -267,7 +267,7 @@ public OperationResult(TResult resultObject) : base()
267267 /// <summary>
268268 /// Gets or sets the related result object of the operation.
269269 /// </summary>
270- public TResult ResultObject { get ; set ; }
270+ public TResult ? ResultObject { get ; set ; }
271271
272272 /// <summary>
273273 /// This method will append an error with a specific `user-friendly` message to this operation result instance.
@@ -334,6 +334,33 @@ public OperationResult<TResult> AppendErrorMessages<TOther>(TOther otherOperatio
334334 return this ;
335335 }
336336
337+ /// <summary>
338+ /// Creates an instance of <see cref="OperationResult{TResult}"/> and appends the passed error message details to it's internal error collection.
339+ /// </summary>
340+ /// <param name="message">A message to append to the internal errors collection.</param>
341+ /// <param name="code">An optional code to include in the error.</param>
342+ /// <param name="logLevel">A log event level. Defaults to Error.</param>
343+ /// <param name="details">An optional detail message to add to the error.</param>
344+ /// <param name="logger">An optional instance of <see cref="ILogger"/>.</param>
345+ /// <returns>An <see cref="OperationResult{TResult}"/> containing the passed exception.</returns>
346+ public static new OperationResult < TResult > FromError ( string message , int ? code = null , LogLevel logLevel = LogLevel . Error , string ? details = null , ILogger ? logger = null )
347+ {
348+ var result = new OperationResult < TResult > ( logger ) ;
349+ return result . AppendError ( message , code , logLevel , details ) ;
350+ }
351+
352+ /// <summary>
353+ /// Creates an instance of <see cref="OperationResult"/> and appends the passed exception to it's error collection.
354+ /// </summary>
355+ /// <param name="exception">The <see cref="Exception"/> to append.</param>
356+ /// <param name="logger">An optional instance of <see cref="ILogger"/>.</param>
357+ /// <returns>An <see cref="OperationResult{TResult}"/> containing the passed exception.</returns>
358+ public static new OperationResult < TResult > FromException ( Exception exception , ILogger ? logger = null )
359+ {
360+ var result = new OperationResult < TResult > ( logger ) ;
361+ return result . AppendException ( exception ) ;
362+ }
363+
337364 /// <summary>
338365 /// Sets related object to the provided operation result and returns itself.
339366 /// </summary>
0 commit comments