You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace GeoSigmaDrawLib
|
|
{
|
|
/// <summary>
|
|
/// 操作结果类
|
|
/// 没有专门的工具模块,暂时先放这里
|
|
/// </summary>
|
|
public class OperationResult
|
|
{
|
|
private OperationResult(bool success, string error)
|
|
{
|
|
IsSuccess = success;
|
|
ErrorMessage = error;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 是否成功
|
|
/// </summary>
|
|
public bool IsSuccess { get; }
|
|
|
|
/// <summary>
|
|
/// 错误消息,如果失败,这里会放上原因
|
|
/// </summary>
|
|
public string ErrorMessage { get; }
|
|
|
|
/// <summary>
|
|
/// 成功
|
|
/// </summary>
|
|
/// <returns>表示成功的操作结果对象</returns>
|
|
public static OperationResult Success()
|
|
{
|
|
return new OperationResult(true, string.Empty);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 失败
|
|
/// </summary>
|
|
/// <param name="message">失败消息</param>
|
|
/// <returns>带失败消息的操作结果对象</returns>
|
|
public static OperationResult Fail(string message)
|
|
{
|
|
if (string.IsNullOrEmpty(message))
|
|
{
|
|
throw new ArgumentException("失败时必须提供错误消息", nameof(message));
|
|
}
|
|
|
|
return new OperationResult(false, message);
|
|
}
|
|
}
|
|
}
|