@@ -13,70 +13,70 @@ namespace NHibernate.Dialect.Function
13
13
public class BitwiseNativeOperation : ISQLFunction
14
14
{
15
15
private readonly string _sqlOpToken ;
16
- private readonly bool _isNot ;
16
+ private readonly bool _isUnary ;
17
17
18
18
/// <summary>
19
- /// creates an instance using the giving token
19
+ /// Creates an instance using the giving token.
20
20
/// </summary>
21
21
/// <param name="sqlOpToken">
22
- /// The operation token
22
+ /// The operation token.
23
23
/// </param>
24
24
/// <remarks>
25
- /// Use this constructor only if the token DOES NOT represent a NOT-Operation
25
+ /// Use this constructor only if the token DOES NOT represent an unary operator.
26
26
/// </remarks>
27
27
public BitwiseNativeOperation ( string sqlOpToken )
28
28
: this ( sqlOpToken , false )
29
29
{
30
30
}
31
31
32
32
/// <summary>
33
- /// creates an instance using the giving token and the flag indicating a NOT-Operation
33
+ /// Creates an instance using the giving token and the flag indicating if it is an unary operator.
34
34
/// </summary>
35
- /// <param name="sqlOpToken"></param>
36
- /// <param name="isNot"> </param>
37
- public BitwiseNativeOperation ( string sqlOpToken , bool isNot )
35
+ /// <param name="sqlOpToken">The operation token. </param>
36
+ /// <param name="isUnary">Whether the operation is unary or not. </param>
37
+ public BitwiseNativeOperation ( string sqlOpToken , bool isUnary )
38
38
{
39
39
_sqlOpToken = sqlOpToken ;
40
- _isNot = isNot ;
40
+ _isUnary = isUnary ;
41
41
}
42
42
43
43
#region ISQLFunction Members
44
44
45
+ /// <inheritdoc />
45
46
public IType ReturnType ( IType columnType , IMapping mapping )
46
47
{
47
48
return NHibernateUtil . Int64 ;
48
49
}
49
50
50
- public bool HasArguments
51
- {
52
- get { return true ; }
53
- }
51
+ /// <inheritdoc />
52
+ public bool HasArguments => true ;
54
53
55
- public bool HasParenthesesIfNoArguments
56
- {
57
- get { return false ; }
58
- }
54
+ /// <inheritdoc />
55
+ public bool HasParenthesesIfNoArguments => false ;
59
56
57
+ /// <inheritdoc />
60
58
public SqlString Render ( IList args , ISessionFactoryImplementor factory )
61
59
{
60
+ if ( args . Count == 0 )
61
+ throw new ArgumentException ( "Function argument list cannot be empty" , nameof ( args ) ) ;
62
+
62
63
var sqlBuffer = new SqlStringBuilder ( ) ;
63
- var arguments = new Queue ( args ) ;
64
64
65
- if ( _isNot == false )
66
- AddToBuffer ( arguments . Dequeue ( ) , sqlBuffer ) ;
65
+ if ( ! _isUnary )
66
+ AddToBuffer ( args [ 0 ] , sqlBuffer ) ;
67
67
68
- AddToBuffer ( string . Format ( " {0} " , _sqlOpToken ) , sqlBuffer ) ;
69
- while ( arguments . Count > 0 )
68
+ sqlBuffer . Add ( " " ) . Add ( _sqlOpToken ) . Add ( " " ) ;
69
+ for ( var i = _isUnary ? 0 : 1 ; i < args . Count ; i ++ )
70
70
{
71
- AddToBuffer ( arguments . Dequeue ( ) , sqlBuffer ) ;
71
+ AddToBuffer ( args [ i ] , sqlBuffer ) ;
72
72
}
73
73
74
74
return sqlBuffer . ToSqlString ( ) ;
75
75
}
76
76
77
77
#endregion
78
78
79
- private void AddToBuffer ( object arg , SqlStringBuilder buffer )
79
+ private static void AddToBuffer ( object arg , SqlStringBuilder buffer )
80
80
{
81
81
if ( arg is Parameter || arg is SqlString )
82
82
buffer . AddObject ( arg ) ;
0 commit comments