-
Notifications
You must be signed in to change notification settings - Fork 0
Result Object
Youssef Sellami edited this page Sep 12, 2024
·
5 revisions
1- Result:
this type is used to describe the execution status of a void method with no return value.
the object itself is very simple and has a few properties.
public class Result
{
/// <summary>
/// Get the Status of the result.
/// </summary>
public ResultStatus Status { get; }
/// <summary>
/// get or set the message that describes the result of the operation.
/// </summary>
public string Message { get; set; }
/// <summary>
/// get or set the error code that describes the result of the operation.
/// </summary>
public string Code { get; set; }
/// <summary>
/// Get or set a unique log trace code used to trace the result in logs.
/// </summary>
public string LogTraceCode { get; set; }
/// <summary>
/// get the list of errors associated with the operation result.
/// </summary>
public ICollection<ResultError> Errors { get; }
/// <summary>
/// Gets a collection of key/data pairs that provide additional
/// metadata information about the operation result.
/// </summary>
public IDictionary<string, object> MetaData { get; }
}
-
Result.Status:
the status property is an enum with two values: Failed & Succeed, it is used to define the Result status. -
Result.Message:
the message property is used to describe the result status, we only using it if the result has a Failed status, to describe in human-readable format what went wrong. -
Result.Code:
the code property is used to describe the result status, we use this property to enable machine-to-machine communication. utilizing a predefined list of error codes, I already have a predefined list of common codes (you can find them in ResultCode), and you can add your own. -
Result.LogTraceCode:
the log trace code property is a random unique string used as code and attached to the result operation to locate the result in your logs. -
Result.Errors:
the error collection property is used to attach a more detailed explanation in terms of errors associated with result failure. -
Result.MetaData:
the metadata property is a key-value pair collection to attach some additional data with the operation result.
2- Result<>:
this type is a generic type that drives from Result and is used to describe the execution status of a method with a return value.
the object has only one property over the Result type.
public class Result<TData> : Result
{
/// <summary>
/// the data associated with the result.
/// </summary>
public TData Data { get; }
}
-
Result<>.Data:
The data property is used to store the operation output data.