Created
November 14, 2016 09:38
-
-
Save pawelklimczyk/958f74a96e359bdb721b53065b3cd0ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Generic class working as a wrapper | |
/// </summary> | |
/// <typeparam name="T">type</typeparam> | |
public class OperationResult<T> | |
{ | |
/// <summary> | |
/// Result value | |
/// </summary> | |
public T Result { get; set; } | |
/// <summary> | |
/// Operation status | |
/// </summary> | |
public OperationalStatus Status { get; set; } | |
/// <summary> | |
/// Extra info send with operation result (optional) | |
/// </summary> | |
public string Message { get; set; } | |
public static OperationResult<T> Error(T value = default(T), string message = "") | |
{ | |
return new OperationResult<T> | |
{ | |
Result = value, | |
Message = message, | |
Status = OperationalStatus.Error | |
}; | |
} | |
public static OperationResult<T> Success(T value = default(T), string message = "") | |
{ | |
return new OperationResult<T> | |
{ | |
Result = value, | |
Message = message, | |
Status = OperationalStatus.Success | |
}; | |
} | |
} | |
/// <summary> | |
/// Status of executed operation | |
/// </summary> | |
public enum OperationalStatus | |
{ | |
Success, | |
Warning, | |
Error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment