33namespace Cnblogs . Architecture . Ddd . Cqrs . Abstractions ;
44
55/// <summary>
6- /// 命令返回的结果。
6+ /// Response returned by <see cref="ICommand{TError}"/>.
77/// </summary>
88public abstract record CommandResponse : IValidationResponse , ILockableResponse
99{
1010 /// <summary>
11- /// 是否出现验证错误。
11+ /// Check if validation fails.
1212 /// </summary>
1313 public bool IsValidationError { get ; init ; }
1414
1515 /// <summary>
16- /// 是否出现并发错误。
16+ /// Check if concurrent error happened.
1717 /// </summary>
1818 public bool IsConcurrentError { get ; init ; }
1919
2020 /// <summary>
21- /// 错误信息。
21+ /// The error message returned by handler, return empty if no error or no error message.
2222 /// </summary>
23+ /// <remarks>
24+ /// Do not rely on this property to determine if executed successful, use <see cref="IsSuccess"/> for this purpose.
25+ /// </remarks>
2326 public string ErrorMessage { get ; init ; } = string . Empty ;
2427
2528 /// <inheritdoc />
@@ -29,55 +32,55 @@ public abstract record CommandResponse : IValidationResponse, ILockableResponse
2932 public bool LockAcquired { get ; set ; }
3033
3134 /// <summary>
32- /// 执行是否成功。
35+ /// Check if command executed successfully.
3336 /// </summary>
34- /// <returns></returns>
37+ /// <returns>Return true if executed successfully, else return false. </returns>
3538 public virtual bool IsSuccess ( )
3639 {
3740 return IsValidationError == false && string . IsNullOrEmpty ( ErrorMessage ) && IsConcurrentError == false ;
3841 }
3942
4043 /// <summary>
41- /// 获取错误信息。
44+ /// Get error message.
4245 /// </summary>
43- /// <returns></returns>
46+ /// <returns>The error message, return <see cref="string.Empty"/> if no error. </returns>
4447 public virtual string GetErrorMessage ( ) => ErrorMessage ;
4548}
4649
4750/// <summary>
48- /// 命令返回的结果。
51+ /// Response returned by <see cref="ICommand{TError}"/>.
4952/// </summary>
50- /// <typeparam name="TError">错误枚举类型。 </typeparam>
53+ /// <typeparam name="TError">The enumeration presenting errors. </typeparam>
5154public record CommandResponse < TError > : CommandResponse
5255 where TError : Enumeration
5356{
5457 /// <summary>
55- /// 构造一个 <see cref="CommandResponse{TError}" />。
58+ /// Create a successful <see cref="CommandResponse{TError}" />.
5659 /// </summary>
5760 public CommandResponse ( )
5861 {
5962 ErrorCode = default ;
6063 }
6164
6265 /// <summary>
63- /// 构造一个 <see cref="CommandResponse{TError}" />。
66+ /// Create a <see cref="CommandResponse{TError}" /> with given error.
6467 /// </summary>
65- /// <param name="errorCode">错误码。 </param>
68+ /// <param name="errorCode">The error. </param>
6669 public CommandResponse ( TError errorCode )
6770 {
6871 ErrorCode = errorCode ;
6972 }
7073
7174 /// <summary>
72- /// 错误码。
75+ /// The error returned by handler, can be null if execution succeeded.
7376 /// </summary>
7477 public TError ? ErrorCode { get ; set ; }
7578
7679 /// <summary>
77- /// 构造一个代表命令执行失败的 <see cref="CommandResponse{TError}" />
80+ /// Create a failed <see cref="CommandResponse{TError}" /> with given error.
7881 /// </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>
8184 public static CommandResponse < TError > Fail ( TError errorCode )
8285 {
8386 return new CommandResponse < TError > ( errorCode ) ;
@@ -96,77 +99,80 @@ public override string GetErrorMessage()
9699 }
97100
98101 /// <summary>
99- /// 构造一个代表命令执行成功的 <see cref="CommandResponse{TError}" />。
102+ /// Create a successful <see cref="CommandResponse{TError}" />.
100103 /// </summary>
101- /// <returns>代表命令执行成功的 <see cref="CommandResponse{TError}" /></returns>
104+ /// <returns>A successful <see cref="CommandResponse{TError}" />. </returns>
102105 public static CommandResponse < TError > Success ( )
103106 {
104107 return new CommandResponse < TError > ( ) ;
105108 }
106109}
107110
108111/// <summary>
109- /// 命令返回的结果。
112+ /// Response returned by <see cref="ICommand{TError}"/>.
110113/// </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>
113116public record CommandResponse < TView , TError > : CommandResponse < TError > , IObjectResponse
114117 where TError : Enumeration
115118{
116119 /// <summary>
117- /// 构造一个 <see cref="CommandResponse{TView,TError}" />。
120+ /// Create a <see cref="CommandResponse{TView,TError}" />.
118121 /// </summary>
119122 public CommandResponse ( )
120123 {
121124 }
122125
123126 /// <summary>
124- /// 构造一个 <see cref="CommandResponse{TError}" />。
127+ /// Create a <see cref="CommandResponse{TError}" /> with given error.
125128 /// </summary>
126- /// <param name="errorCode">错误码。 </param>
129+ /// <param name="errorCode">The error. </param>
127130 public CommandResponse ( TError errorCode )
128131 : base ( errorCode )
129132 {
130133 }
131134
132135 /// <summary>
133- /// 构造一个 <see cref="CommandResponse{TError}" />。
136+ /// Create a <see cref="CommandResponse{TError}" /> with given model.
134137 /// </summary>
135- /// <param name="response">命令返回结果。 </param>
138+ /// <param name="response">The execution result. </param>
136139 private CommandResponse ( TView response )
137140 {
138141 Response = response ;
139142 }
140143
141144 /// <summary>
142- /// 命令执行结果。
145+ /// The result been returned by command handler.
143146 /// </summary>
147+ /// <remarks>
148+ /// This property can be null even if execution completed with no error.
149+ /// </remarks>
144150 public TView ? Response { get ; }
145151
146152 /// <summary>
147- /// 构造一个代表执行失败的 <see cref="CommandResponse{TView,TError}" />。
153+ /// Create a <see cref="CommandResponse{TView,TError}" /> with given error.
148154 /// </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>
151157 public static new CommandResponse < TView , TError > Fail ( TError errorCode )
152158 {
153159 return new CommandResponse < TView , TError > ( errorCode ) ;
154160 }
155161
156162 /// <summary>
157- /// 构造一个代表执行成功的 <see cref="CommandResponse{TView,TError}" />。
163+ /// Create a <see cref="CommandResponse{TView,TError}" /> with no result nor error.
158164 /// </summary>
159- /// <returns>代表执行成功的 <see cref="CommandResponse{TView,TError}" />。</returns>
165+ /// <returns>The <see cref="CommandResponse{TView,TError}" />。</returns>
160166 public static new CommandResponse < TView , TError > Success ( )
161167 {
162168 return new CommandResponse < TView , TError > ( ) ;
163169 }
164170
165171 /// <summary>
166- /// 构造一个代表执行成功的 <see cref="CommandResponse{TView,TError}" />。
172+ /// Create a <see cref="CommandResponse{TView,TError}" /> with given result.
167173 /// </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>
170176 public static CommandResponse < TView , TError > Success ( TView view )
171177 {
172178 return new CommandResponse < TView , TError > ( view ) ;
0 commit comments