138 lines
5.5 KiB
C#
138 lines
5.5 KiB
C#
namespace FoodsharingSiegen.Contracts
|
|
{
|
|
#region OperationResult<T>
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Encapsulates the result of an operation. </summary>
|
|
///
|
|
/// <remarks> A Beging, 20.10.2021. </remarks>
|
|
///
|
|
/// <typeparam name="T"> Generic type parameter. </typeparam>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public class OperationResult<T>
|
|
{
|
|
#region Public Properties
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Gets or sets the exception. </summary>
|
|
///
|
|
/// <value> The exception. </value>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public Exception? Exception { get; set; }
|
|
|
|
/// <summary> Returns an error message if the exception is set </summary>
|
|
public string ErrorMessage
|
|
{
|
|
get
|
|
{
|
|
if (Success) return string.Empty;
|
|
return Exception != null ? Exception.GetBaseException().Message : "Fehler";
|
|
}
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Gets or sets a value indicating whether the success. </summary>
|
|
///
|
|
/// <value> True if success, false if not. </value>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public bool Success { get; set; } = true;
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Gets or sets the data. </summary>
|
|
///
|
|
/// <value> The data. </value>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public T? Data { get; set; }
|
|
|
|
#endregion Public Properties
|
|
|
|
#region Constructors
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Constructor. </summary>
|
|
///
|
|
/// <remarks> A Beging, 20.10.2021. </remarks>
|
|
///
|
|
/// <param name="exception"> The exception. </param>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public OperationResult(Exception exception)
|
|
{
|
|
Success = false;
|
|
Exception = exception;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Constructor. </summary>
|
|
///
|
|
/// <remarks> A Beging, 20.10.2021. </remarks>
|
|
///
|
|
/// <param name="data"> The data. </param>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public OperationResult(T data)
|
|
{
|
|
Data = data;
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Default constructor. </summary>
|
|
///
|
|
/// <remarks> A Beging, 22.10.2021. </remarks>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public OperationResult()
|
|
{
|
|
|
|
}
|
|
|
|
#endregion Constructors
|
|
}
|
|
|
|
#endregion OperationResult<T>
|
|
|
|
#region OperationResult
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Encapsulates the result of an operation. </summary>
|
|
///
|
|
/// <remarks> A Beging, 20.10.2021. </remarks>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public class OperationResult : OperationResult<object>
|
|
{
|
|
#region Constructors
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Constructor. </summary>
|
|
///
|
|
/// <remarks> A Beging, 20.10.2021. </remarks>
|
|
///
|
|
/// <param name="exception"> The exception. </param>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public OperationResult(Exception exception) : base(exception)
|
|
{
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Constructor. </summary>
|
|
///
|
|
/// <remarks> A Beging, 20.10.2021. </remarks>
|
|
///
|
|
/// <param name="data"> True to data. </param>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public OperationResult(bool data) : base(data)
|
|
{
|
|
}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
/// <summary> Default constructor. </summary>
|
|
///
|
|
/// <remarks> A Beging, 22.10.2021. </remarks>
|
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
public OperationResult()
|
|
{
|
|
|
|
}
|
|
|
|
#endregion Constructors
|
|
}
|
|
|
|
#endregion OperationResult
|
|
} |