38 lines
786 B
C#
38 lines
786 B
C#
namespace Blahblah.Library.Network;
|
|
|
|
public class NetworkResult<T>
|
|
{
|
|
public T? Result { get; }
|
|
|
|
public Exception? Exception { get; }
|
|
|
|
public NetworkResult(T? obj, Exception? exception = null)
|
|
{
|
|
Result = obj;
|
|
Exception = exception;
|
|
}
|
|
|
|
public void ThrowIfException(bool throwIfDefault = false)
|
|
{
|
|
if (Exception != null)
|
|
{
|
|
throw Exception;
|
|
}
|
|
if (throwIfDefault && Equals(Result, default))
|
|
{
|
|
throw new Exception($"Network result is {{{default}}}");
|
|
}
|
|
}
|
|
|
|
public static implicit operator NetworkResult<T>(T? obj)
|
|
{
|
|
return new(obj);
|
|
}
|
|
|
|
public static implicit operator NetworkResult<T>(Exception ex)
|
|
{
|
|
return new(default, ex);
|
|
}
|
|
}
|
|
|