@@ -1238,12 +1238,12 @@ protected virtual object VisitBinary(BinaryExpression b)
1238
1238
var operand = BindOperant ( b . NodeType ) ; //sep= " " ??
1239
1239
if ( operand == "AND" || operand == "OR" )
1240
1240
{
1241
- if ( IsNeedCompareToTrue ( b . Left ) )
1241
+ if ( IsBooleanComparison ( b . Left ) )
1242
1242
left = new PartialSqlString ( string . Format ( "{0}={1}" , VisitMemberAccess ( ( MemberExpression ) b . Left ) , GetQuotedTrueValue ( ) ) ) ;
1243
1243
else
1244
1244
left = Visit ( b . Left ) ;
1245
1245
1246
- if ( IsNeedCompareToTrue ( b . Right ) )
1246
+ if ( IsBooleanComparison ( b . Right ) )
1247
1247
right = new PartialSqlString ( string . Format ( "{0}={1}" , VisitMemberAccess ( ( MemberExpression ) b . Right ) , GetQuotedTrueValue ( ) ) ) ;
1248
1248
else
1249
1249
right = Visit ( b . Right ) ;
@@ -1354,17 +1354,16 @@ protected virtual object VisitBinary(BinaryExpression b)
1354
1354
/// <summary>
1355
1355
/// Determines whether the expression is the parameter inside MemberExpression which should be compared with TrueExpression.
1356
1356
/// </summary>
1357
- /// <param name="e">The specified expression.</param>
1358
1357
/// <returns>Returns true if the specified expression is the parameter inside MemberExpression which should be compared with TrueExpression;
1359
1358
/// otherwise, false.</returns>
1360
- protected virtual bool IsNeedCompareToTrue ( Expression e )
1359
+ protected virtual bool IsBooleanComparison ( Expression e )
1361
1360
{
1362
1361
if ( ! ( e is MemberExpression ) ) return false ;
1363
1362
1364
1363
var m = ( MemberExpression ) e ;
1365
1364
1366
1365
if ( m . Member . DeclaringType . IsNullableType ( ) &&
1367
- m . Member . Name == "HasValue" ) //nameof(Nullable<bool>.HasValue))
1366
+ m . Member . Name == "HasValue" ) //nameof(Nullable<bool>.HasValue)
1368
1367
return false ;
1369
1368
1370
1369
return IsParameterAccess ( m ) ;
@@ -1373,7 +1372,6 @@ protected virtual bool IsNeedCompareToTrue(Expression e)
1373
1372
/// <summary>
1374
1373
/// Determines whether the expression is the parameter.
1375
1374
/// </summary>
1376
- /// <param name="e">The specified expression.</param>
1377
1375
/// <returns>Returns true if the specified expression is parameter;
1378
1376
/// otherwise, false.</returns>
1379
1377
protected virtual bool IsParameterAccess ( Expression e )
@@ -1382,9 +1380,8 @@ protected virtual bool IsParameterAccess(Expression e)
1382
1380
}
1383
1381
1384
1382
/// <summary>
1385
- /// Determines whether the expression is the parameter or convert .
1383
+ /// Determines whether the expression is a Parameter or Convert Expression .
1386
1384
/// </summary>
1387
- /// <param name="e">The specified expression.</param>
1388
1385
/// <returns>Returns true if the specified expression is parameter or convert;
1389
1386
/// otherwise, false.</returns>
1390
1387
protected virtual bool IsParameterOrConvertAccess ( Expression e )
@@ -1398,38 +1395,42 @@ protected bool CheckExpressionForTypes(Expression e, ExpressionType[] types)
1398
1395
{
1399
1396
if ( types . Contains ( e . NodeType ) )
1400
1397
{
1401
- var isSubExprAccess = e is UnaryExpression &&
1402
- ( ( UnaryExpression ) e ) . Operand is IndexExpression ;
1398
+ var subUnaryExpr = e as UnaryExpression ;
1399
+ var isSubExprAccess = subUnaryExpr != null && subUnaryExpr . Operand is IndexExpression ;
1403
1400
1404
1401
if ( ! isSubExprAccess )
1405
1402
return true ;
1406
1403
}
1407
1404
1408
- if ( e is BinaryExpression )
1405
+ var binaryExpr = e as BinaryExpression ;
1406
+ if ( binaryExpr != null )
1409
1407
{
1410
- if ( CheckExpressionForTypes ( ( ( BinaryExpression ) e ) . Left , types ) )
1408
+ if ( CheckExpressionForTypes ( binaryExpr . Left , types ) )
1411
1409
return true ;
1412
1410
1413
- if ( CheckExpressionForTypes ( ( ( BinaryExpression ) e ) . Right , types ) )
1411
+ if ( CheckExpressionForTypes ( binaryExpr . Right , types ) )
1414
1412
return true ;
1415
1413
}
1416
1414
1417
- if ( e is MethodCallExpression )
1415
+ var methodCallExpr = e as MethodCallExpression ;
1416
+ if ( methodCallExpr != null )
1418
1417
{
1419
- for ( int i = 0 ; i < ( ( MethodCallExpression ) e ) . Arguments . Count ; i ++ )
1418
+ for ( var i = 0 ; i < methodCallExpr . Arguments . Count ; i ++ )
1420
1419
{
1421
- if ( CheckExpressionForTypes ( ( ( MethodCallExpression ) e ) . Arguments [ 0 ] , types ) )
1420
+ if ( CheckExpressionForTypes ( methodCallExpr . Arguments [ 0 ] , types ) )
1422
1421
return true ;
1423
1422
}
1424
1423
}
1425
1424
1426
- if ( e is UnaryExpression )
1425
+ var unaryExpr = e as UnaryExpression ;
1426
+ if ( unaryExpr != null )
1427
1427
{
1428
- if ( CheckExpressionForTypes ( ( ( UnaryExpression ) e ) . Operand , types ) )
1428
+ if ( CheckExpressionForTypes ( unaryExpr . Operand , types ) )
1429
1429
return true ;
1430
1430
}
1431
1431
1432
- e = e is MemberExpression ? ( ( MemberExpression ) e ) . Expression : null ;
1432
+ var memberExpr = e as MemberExpression ;
1433
+ e = memberExpr != null ? memberExpr . Expression : null ;
1433
1434
}
1434
1435
1435
1436
return false ;
0 commit comments