3
3
namespace Cnblogs . Architecture . Ddd . Cqrs . Abstractions ;
4
4
5
5
/// <summary>
6
- /// 命令返回的结果。
6
+ /// Response returned by <see cref="ICommand{TError}"/>.
7
7
/// </summary>
8
8
public abstract record CommandResponse : IValidationResponse , ILockableResponse
9
9
{
10
10
/// <summary>
11
- /// 是否出现验证错误。
11
+ /// Check if validation fails.
12
12
/// </summary>
13
13
public bool IsValidationError { get ; init ; }
14
14
15
15
/// <summary>
16
- /// 是否出现并发错误。
16
+ /// Check if concurrent error happened.
17
17
/// </summary>
18
18
public bool IsConcurrentError { get ; init ; }
19
19
20
20
/// <summary>
21
- /// 错误信息。
21
+ /// The error message returned by handler, return empty if no error or no error message.
22
22
/// </summary>
23
+ /// <remarks>
24
+ /// Do not rely on this property to determine if executed successful, use <see cref="IsSuccess"/> for this purpose.
25
+ /// </remarks>
23
26
public string ErrorMessage { get ; init ; } = string . Empty ;
24
27
25
28
/// <inheritdoc />
@@ -29,55 +32,55 @@ public abstract record CommandResponse : IValidationResponse, ILockableResponse
29
32
public bool LockAcquired { get ; set ; }
30
33
31
34
/// <summary>
32
- /// 执行是否成功。
35
+ /// Check if command executed successfully.
33
36
/// </summary>
34
- /// <returns></returns>
37
+ /// <returns>Return true if executed successfully, else return false. </returns>
35
38
public virtual bool IsSuccess ( )
36
39
{
37
40
return IsValidationError == false && string . IsNullOrEmpty ( ErrorMessage ) && IsConcurrentError == false ;
38
41
}
39
42
40
43
/// <summary>
41
- /// 获取错误信息。
44
+ /// Get error message.
42
45
/// </summary>
43
- /// <returns></returns>
46
+ /// <returns>The error message, return <see cref="string.Empty"/> if no error. </returns>
44
47
public virtual string GetErrorMessage ( ) => ErrorMessage ;
45
48
}
46
49
47
50
/// <summary>
48
- /// 命令返回的结果。
51
+ /// Response returned by <see cref="ICommand{TError}"/>.
49
52
/// </summary>
50
- /// <typeparam name="TError">错误枚举类型。 </typeparam>
53
+ /// <typeparam name="TError">The enumeration presenting errors. </typeparam>
51
54
public record CommandResponse < TError > : CommandResponse
52
55
where TError : Enumeration
53
56
{
54
57
/// <summary>
55
- /// 构造一个 <see cref="CommandResponse{TError}" />。
58
+ /// Create a successful <see cref="CommandResponse{TError}" />.
56
59
/// </summary>
57
60
public CommandResponse ( )
58
61
{
59
62
ErrorCode = default ;
60
63
}
61
64
62
65
/// <summary>
63
- /// 构造一个 <see cref="CommandResponse{TError}" />。
66
+ /// Create a <see cref="CommandResponse{TError}" /> with given error.
64
67
/// </summary>
65
- /// <param name="errorCode">错误码。 </param>
68
+ /// <param name="errorCode">The error. </param>
66
69
public CommandResponse ( TError errorCode )
67
70
{
68
71
ErrorCode = errorCode ;
69
72
}
70
73
71
74
/// <summary>
72
- /// 错误码。
75
+ /// The error returned by handler, can be null if execution succeeded.
73
76
/// </summary>
74
77
public TError ? ErrorCode { get ; set ; }
75
78
76
79
/// <summary>
77
- /// 构造一个代表命令执行失败的 <see cref="CommandResponse{TError}" />
80
+ /// Create a failed <see cref="CommandResponse{TError}" /> with given error.
78
81
/// </summary>
79
- /// <param name="errorCode">错误码。 </param>
80
- /// <returns>代表命令执行失败的 <see cref="CommandResponse{TError}" /></returns>
82
+ /// <param name="errorCode">The error. </param>
83
+ /// <returns>A failed <see cref="CommandResponse{TError}" /> with given error. </returns>
81
84
public static CommandResponse < TError > Fail ( TError errorCode )
82
85
{
83
86
return new CommandResponse < TError > ( errorCode ) ;
@@ -96,77 +99,80 @@ public override string GetErrorMessage()
96
99
}
97
100
98
101
/// <summary>
99
- /// 构造一个代表命令执行成功的 <see cref="CommandResponse{TError}" />。
102
+ /// Create a successful <see cref="CommandResponse{TError}" />.
100
103
/// </summary>
101
- /// <returns>代表命令执行成功的 <see cref="CommandResponse{TError}" /></returns>
104
+ /// <returns>A successful <see cref="CommandResponse{TError}" />. </returns>
102
105
public static CommandResponse < TError > Success ( )
103
106
{
104
107
return new CommandResponse < TError > ( ) ;
105
108
}
106
109
}
107
110
108
111
/// <summary>
109
- /// 命令返回的结果。
112
+ /// Response returned by <see cref="ICommand{TError}"/>.
110
113
/// </summary>
111
- /// <typeparam name="TView">命令执行成功时返回的结果类型。 </typeparam>
112
- /// <typeparam name="TError">错误类型。 </typeparam>
114
+ /// <typeparam name="TView">The model type been returned if execution completed without error. </typeparam>
115
+ /// <typeparam name="TError">The enumeration type representing errors. </typeparam>
113
116
public record CommandResponse < TView , TError > : CommandResponse < TError > , IObjectResponse
114
117
where TError : Enumeration
115
118
{
116
119
/// <summary>
117
- /// 构造一个 <see cref="CommandResponse{TView,TError}" />。
120
+ /// Create a <see cref="CommandResponse{TView,TError}" />.
118
121
/// </summary>
119
122
public CommandResponse ( )
120
123
{
121
124
}
122
125
123
126
/// <summary>
124
- /// 构造一个 <see cref="CommandResponse{TError}" />。
127
+ /// Create a <see cref="CommandResponse{TError}" /> with given error.
125
128
/// </summary>
126
- /// <param name="errorCode">错误码。 </param>
129
+ /// <param name="errorCode">The error. </param>
127
130
public CommandResponse ( TError errorCode )
128
131
: base ( errorCode )
129
132
{
130
133
}
131
134
132
135
/// <summary>
133
- /// 构造一个 <see cref="CommandResponse{TError}" />。
136
+ /// Create a <see cref="CommandResponse{TError}" /> with given model.
134
137
/// </summary>
135
- /// <param name="response">命令返回结果。 </param>
138
+ /// <param name="response">The execution result. </param>
136
139
private CommandResponse ( TView response )
137
140
{
138
141
Response = response ;
139
142
}
140
143
141
144
/// <summary>
142
- /// 命令执行结果。
145
+ /// The result been returned by command handler.
143
146
/// </summary>
147
+ /// <remarks>
148
+ /// This property can be null even if execution completed with no error.
149
+ /// </remarks>
144
150
public TView ? Response { get ; }
145
151
146
152
/// <summary>
147
- /// 构造一个代表执行失败的 <see cref="CommandResponse{TView,TError}" />。
153
+ /// Create a <see cref="CommandResponse{TView,TError}" /> with given error.
148
154
/// </summary>
149
- /// <param name="errorCode">错误码。 </param>
150
- /// <returns></returns>
155
+ /// <param name="errorCode">The error. </param>
156
+ /// <returns>A <see cref="CommandResponse{TView, TError}"/> with given error. </returns>
151
157
public static new CommandResponse < TView , TError > Fail ( TError errorCode )
152
158
{
153
159
return new CommandResponse < TView , TError > ( errorCode ) ;
154
160
}
155
161
156
162
/// <summary>
157
- /// 构造一个代表执行成功的 <see cref="CommandResponse{TView,TError}" />。
163
+ /// Create a <see cref="CommandResponse{TView,TError}" /> with no result nor error.
158
164
/// </summary>
159
- /// <returns>代表执行成功的 <see cref="CommandResponse{TView,TError}" />。</returns>
165
+ /// <returns>The <see cref="CommandResponse{TView,TError}" />。</returns>
160
166
public static new CommandResponse < TView , TError > Success ( )
161
167
{
162
168
return new CommandResponse < TView , TError > ( ) ;
163
169
}
164
170
165
171
/// <summary>
166
- /// 构造一个代表执行成功的 <see cref="CommandResponse{TView,TError}" />。
172
+ /// Create a <see cref="CommandResponse{TView,TError}" /> with given result.
167
173
/// </summary>
168
- /// <param name="view">执行结果。 </param>
169
- /// <returns></returns>
174
+ /// <param name="view">The model to return. </param>
175
+ /// <returns>A <see cref="CommandResponse{TView, TError}"/> with given result. </returns>
170
176
public static CommandResponse < TView , TError > Success ( TView view )
171
177
{
172
178
return new CommandResponse < TView , TError > ( view ) ;
0 commit comments