1
我想包括几个扩展基本功能的附加属性,例如public bool Success { get; set; }
或覆盖ErrorCode
以替代返回int
。有这样的可能吗?是否可以在ServiceStack中扩展ResponseStatus类以包含其他属性?
我想包括几个扩展基本功能的附加属性,例如public bool Success { get; set; }
或覆盖ErrorCode
以替代返回int
。有这样的可能吗?是否可以在ServiceStack中扩展ResponseStatus类以包含其他属性?
不能扩展内置类型,但可以使用override the default error handling to use your own error handling。
但作为一个int仅仅是一个严格的字符串,我会亲自把它原样,只需使用一个辅助扩展方法,如:
public static class ResponseStatusExtensions {
public int? ErrorNumber(this ResponseStatus status) {
int errNum;
return int.TryParse(status.ErrorCode, out errNum) ? errNum : (int?)null;
}
}
然后你可以使用它像:
if (response.ResponseStatus.ErrorNumber() == 100) { ... }
我♥ServiceStack – Shagglez