@@ -38,16 +38,22 @@ namespace GameFrameX.Foundation.Extensions;
3838/// <summary>
3939/// 提供对 <see cref="Expression" /> 类型的扩展方法,用于组合和操作表达式树。
4040/// </summary>
41+ /// <remarks>
42+ /// Provides extension methods for the <see cref="Expression" /> type, used for combining and manipulating expression trees.
43+ /// </remarks>
4144public static class ExpressionExtension
4245{
4346 /// <summary>
4447 /// 将两个表达式进行逻辑与运算,使用短路求值。
4548 /// </summary>
46- /// <typeparam name="T">表达式的参数类型。</typeparam>
47- /// <param name="leftExpression">第一个表达式,作为逻辑与运算的左操作数。</param>
48- /// <param name="rightExpression">第二个表达式,作为逻辑与运算的右操作数。</param>
49- /// <returns>一个新的表达式,表示两个输入表达式的逻辑与运算结果。</returns>
50- /// <exception cref="ArgumentNullException">当 leftExpression 或 rightExpression 为 null 时抛出。</exception>
49+ /// <remarks>
50+ /// Performs a logical AND operation on two expressions using short-circuit evaluation.
51+ /// </remarks>
52+ /// <typeparam name="T">表达式的参数类型 / The parameter type of the expression.</typeparam>
53+ /// <param name="leftExpression">第一个表达式,作为逻辑与运算的左操作数 / The first expression, serving as the left operand of the logical AND operation.</param>
54+ /// <param name="rightExpression">第二个表达式,作为逻辑与运算的右操作数 / The second expression, serving as the right operand of the logical AND operation.</param>
55+ /// <returns>一个新的表达式,表示两个输入表达式的逻辑与运算结果 / A new expression representing the logical AND result of the two input expressions.</returns>
56+ /// <exception cref="ArgumentNullException">当 <paramref name="leftExpression"/> 或 <paramref name="rightExpression"/> 为 <c>null</c> 时抛出 / Thrown when <paramref name="leftExpression"/> or <paramref name="rightExpression"/> is <c>null</c>.</exception>
5157 public static Expression < Func < T , bool > > And < T > ( this Expression < Func < T , bool > > leftExpression , Expression < Func < T , bool > > rightExpression )
5258 {
5359 ArgumentNullException . ThrowIfNull ( leftExpression , nameof ( leftExpression ) ) ;
@@ -62,14 +68,18 @@ public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> le
6268
6369 /// <summary>
6470 /// 根据条件将两个表达式进行逻辑与运算,使用短路求值。
65- /// 当条件为false时 ,仅返回左表达式;当条件为true时 ,返回两个表达式的逻辑与运算结果。
71+ /// 当条件为 false 时 ,仅返回左表达式;当条件为 true 时 ,返回两个表达式的逻辑与运算结果。
6672 /// </summary>
67- /// <typeparam name="T">表达式的参数类型。</typeparam>
68- /// <param name="leftExpression">第一个表达式,作为逻辑与运算的左操作数。</param>
69- /// <param name="condition">决定是否执行逻辑与运算的条件委托。</param>
70- /// <param name="rightExpression">第二个表达式,作为逻辑与运算的右操作数。</param>
71- /// <returns>当条件为true时返回两个表达式的逻辑与运算结果,否则返回左表达式。</returns>
72- /// <exception cref="ArgumentNullException">当任何参数为null时抛出。</exception>
73+ /// <remarks>
74+ /// Performs a logical AND operation on two expressions based on a condition, using short-circuit evaluation.
75+ /// When the condition is false, only the left expression is returned; when the condition is true, the logical AND result of both expressions is returned.
76+ /// </remarks>
77+ /// <typeparam name="T">表达式的参数类型 / The parameter type of the expression.</typeparam>
78+ /// <param name="leftExpression">第一个表达式,作为逻辑与运算的左操作数 / The first expression, serving as the left operand of the logical AND operation.</param>
79+ /// <param name="condition">决定是否执行逻辑与运算的条件委托 / The condition delegate that determines whether to perform the logical AND operation.</param>
80+ /// <param name="rightExpression">第二个表达式,作为逻辑与运算的右操作数 / The second expression, serving as the right operand of the logical AND operation.</param>
81+ /// <returns>当条件为 <c>true</c> 时返回两个表达式的逻辑与运算结果,否则返回左表达式 / Returns the logical AND result of both expressions when the condition is <c>true</c>; otherwise, returns the left expression.</returns>
82+ /// <exception cref="ArgumentNullException">当任何参数为 <c>null</c> 时抛出 / Thrown when any parameter is <c>null</c>.</exception>
7383 public static Expression < Func < T , bool > > AndIf < T > ( this Expression < Func < T , bool > > leftExpression , Func < bool > condition , Expression < Func < T , bool > > rightExpression )
7484 {
7585 ArgumentNullException . ThrowIfNull ( leftExpression , nameof ( leftExpression ) ) ;
@@ -93,11 +103,14 @@ public static Expression<Func<T, bool>> AndIf<T>(this Expression<Func<T, bool>>
93103 /// <summary>
94104 /// 将两个表达式进行逻辑或运算,使用短路求值。
95105 /// </summary>
96- /// <typeparam name="T">表达式的参数类型。</typeparam>
97- /// <param name="leftExpression">第一个表达式,作为逻辑或运算的左操作数。</param>
98- /// <param name="rightExpression">第二个表达式,作为逻辑或运算的右操作数。</param>
99- /// <returns>一个新的表达式,表示两个输入表达式的逻辑或运算结果。</returns>
100- /// <exception cref="ArgumentNullException">当 leftExpression 或 rightExpression 为 null 时抛出。</exception>
106+ /// <remarks>
107+ /// Performs a logical OR operation on two expressions using short-circuit evaluation.
108+ /// </remarks>
109+ /// <typeparam name="T">表达式的参数类型 / The parameter type of the expression.</typeparam>
110+ /// <param name="leftExpression">第一个表达式,作为逻辑或运算的左操作数 / The first expression, serving as the left operand of the logical OR operation.</param>
111+ /// <param name="rightExpression">第二个表达式,作为逻辑或运算的右操作数 / The second expression, serving as the right operand of the logical OR operation.</param>
112+ /// <returns>一个新的表达式,表示两个输入表达式的逻辑或运算结果 / A new expression representing the logical OR result of the two input expressions.</returns>
113+ /// <exception cref="ArgumentNullException">当 <paramref name="leftExpression"/> 或 <paramref name="rightExpression"/> 为 <c>null</c> 时抛出 / Thrown when <paramref name="leftExpression"/> or <paramref name="rightExpression"/> is <c>null</c>.</exception>
101114 public static Expression < Func < T , bool > > Or < T > ( this Expression < Func < T , bool > > leftExpression , Expression < Func < T , bool > > rightExpression )
102115 {
103116 ArgumentNullException . ThrowIfNull ( leftExpression , nameof ( leftExpression ) ) ;
@@ -113,14 +126,18 @@ public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> lef
113126
114127 /// <summary>
115128 /// 根据条件将两个表达式进行逻辑或运算,使用短路求值。
116- /// 当条件为false时 ,仅返回左表达式;当条件为true时 ,返回两个表达式的逻辑或运算结果。
129+ /// 当条件为 false 时 ,仅返回左表达式;当条件为 true 时 ,返回两个表达式的逻辑或运算结果。
117130 /// </summary>
118- /// <typeparam name="T">表达式的参数类型。</typeparam>
119- /// <param name="leftExpression">第一个表达式,作为逻辑或运算的左操作数。</param>
120- /// <param name="condition">决定是否执行逻辑或运算的条件委托。</param>
121- /// <param name="rightExpression">第二个表达式,作为逻辑或运算的右操作数。</param>
122- /// <returns>当条件为true时返回两个表达式的逻辑或运算结果,否则返回左表达式。</returns>
123- /// <exception cref="ArgumentNullException">当任何参数为null时抛出。</exception>
131+ /// <remarks>
132+ /// Performs a logical OR operation on two expressions based on a condition, using short-circuit evaluation.
133+ /// When the condition is false, only the left expression is returned; when the condition is true, the logical OR result of both expressions is returned.
134+ /// </remarks>
135+ /// <typeparam name="T">表达式的参数类型 / The parameter type of the expression.</typeparam>
136+ /// <param name="leftExpression">第一个表达式,作为逻辑或运算的左操作数 / The first expression, serving as the left operand of the logical OR operation.</param>
137+ /// <param name="condition">决定是否执行逻辑或运算的条件委托 / The condition delegate that determines whether to perform the logical OR operation.</param>
138+ /// <param name="rightExpression">第二个表达式,作为逻辑或运算的右操作数 / The second expression, serving as the right operand of the logical OR operation.</param>
139+ /// <returns>当条件为 <c>true</c> 时返回两个表达式的逻辑或运算结果,否则返回左表达式 / Returns the logical OR result of both expressions when the condition is <c>true</c>; otherwise, returns the left expression.</returns>
140+ /// <exception cref="ArgumentNullException">当任何参数为 <c>null</c> 时抛出 / Thrown when any parameter is <c>null</c>.</exception>
124141 public static Expression < Func < T , bool > > OrIf < T > ( this Expression < Func < T , bool > > leftExpression , Func < bool > condition , Expression < Func < T , bool > > rightExpression )
125142 {
126143 ArgumentNullException . ThrowIfNull ( leftExpression , nameof ( leftExpression ) ) ;
@@ -143,13 +160,14 @@ public static Expression<Func<T, bool>> OrIf<T>(this Expression<Func<T, bool>> l
143160 /// <summary>
144161 /// 对表达式进行逻辑非运算,对表达式的结果取反。
145162 /// </summary>
146- /// <typeparam name="T">表达式的参数类型。</typeparam>
147- /// <param name="expr">要进行逻辑非运算的表达式。</param>
148- /// <returns>一个新的表达式,表示输入表达式的逻辑非运算结果。</returns>
149- /// <exception cref="ArgumentNullException">当 expr 为 null 时抛出。</exception>
150163 /// <remarks>
151- /// 如果输入表达式为 x => x > 5,则输出表达式为 x => !(x > 5),等价于 x => x <= 5。
164+ /// Performs a logical NOT operation on an expression, negating the result of the expression.
165+ /// If the input expression is x => x > 5, the output expression is x => !(x > 5), equivalent to x => x <= 5.
152166 /// </remarks>
167+ /// <typeparam name="T">表达式的参数类型 / The parameter type of the expression.</typeparam>
168+ /// <param name="expr">要进行逻辑非运算的表达式 / The expression to perform the logical NOT operation on.</param>
169+ /// <returns>一个新的表达式,表示输入表达式的逻辑非运算结果 / A new expression representing the logical NOT result of the input expression.</returns>
170+ /// <exception cref="ArgumentNullException">当 <paramref name="expr"/> 为 <c>null</c> 时抛出 / Thrown when <paramref name="expr"/> is <c>null</c>.</exception>
153171 public static Expression < Func < T , bool > > Not < T > ( this Expression < Func < T , bool > > expr )
154172 {
155173 ArgumentNullException . ThrowIfNull ( expr , nameof ( expr ) ) ;
@@ -162,15 +180,21 @@ public static Expression<Func<T, bool>> Not<T>(this Expression<Func<T, bool>> ex
162180 /// <summary>
163181 /// 表达式访问器的自定义实现。
164182 /// </summary>
183+ /// <remarks>
184+ /// Custom implementation of the expression visitor.
185+ /// </remarks>
165186 internal sealed class CustomExpressionVisitor : ExpressionVisitor
166187 {
167188 private ParameterExpression _targetParameter ;
168189
169190 /// <summary>
170191 /// 初始化 <see cref="CustomExpressionVisitor" /> 类的新实例。
171192 /// </summary>
172- /// <param name="param">访问器中的参数表达式。不能为 null。</param>
173- /// <exception cref="ArgumentNullException">当 <paramref name="param"/> 为 null 时抛出。</exception>
193+ /// <remarks>
194+ /// Initializes a new instance of the <see cref="CustomExpressionVisitor" /> class.
195+ /// </remarks>
196+ /// <param name="param">访问器中的参数表达式,不能为 <c>null</c> / The parameter expression in the visitor, cannot be <c>null</c>.</param>
197+ /// <exception cref="ArgumentNullException">当 <paramref name="param"/> 为 <c>null</c> 时抛出 / Thrown when <paramref name="param"/> is <c>null</c>.</exception>
174198 public CustomExpressionVisitor ( ParameterExpression param )
175199 {
176200 ArgumentNullException . ThrowIfNull ( param , nameof ( param ) ) ;
@@ -180,14 +204,21 @@ public CustomExpressionVisitor(ParameterExpression param)
180204 /// <summary>
181205 /// 获取或设置访问器中的参数表达式。
182206 /// </summary>
207+ /// <remarks>
208+ /// Gets or sets the parameter expression in the visitor.
209+ /// </remarks>
210+ /// <value>参数表达式 / The parameter expression.</value>
183211 public ParameterExpression Parameter { get ; }
184212
185213 /// <summary>
186- /// 访问Lambda表达式 ,正确处理参数替换。
214+ /// 访问 Lambda 表达式 ,正确处理参数替换。
187215 /// </summary>
188- /// <typeparam name="T">Lambda表达式的委托类型。</typeparam>
189- /// <param name="node">要访问的Lambda表达式。</param>
190- /// <returns>返回访问后的Lambda表达式。</returns>
216+ /// <remarks>
217+ /// Visits the lambda expression, correctly handling parameter substitution.
218+ /// </remarks>
219+ /// <typeparam name="T">Lambda 表达式的委托类型 / The delegate type of the lambda expression.</typeparam>
220+ /// <param name="node">要访问的 Lambda 表达式 / The lambda expression to visit.</param>
221+ /// <returns>返回访问后的 Lambda 表达式 / Returns the visited lambda expression.</returns>
191222 protected override Expression VisitLambda < T > ( Expression < T > node )
192223 {
193224 ArgumentNullException . ThrowIfNull ( node , nameof ( node ) ) ;
@@ -232,8 +263,11 @@ protected override Expression VisitLambda<T>(Expression<T> node)
232263 /// <summary>
233264 /// 访问参数表达式。
234265 /// </summary>
235- /// <param name="node">要访问的参数表达式。</param>
236- /// <returns>返回访问后的表达式。</returns>
266+ /// <remarks>
267+ /// Visits the parameter expression.
268+ /// </remarks>
269+ /// <param name="node">要访问的参数表达式 / The parameter expression to visit.</param>
270+ /// <returns>返回访问后的表达式 / Returns the visited expression.</returns>
237271 protected override Expression VisitParameter ( ParameterExpression node )
238272 {
239273 ArgumentNullException . ThrowIfNull ( node , nameof ( node ) ) ;
0 commit comments