File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -105,23 +105,18 @@ public override void ReplaceWith(SqlExpression expression)
105105 cases . Add ( pair ) ;
106106 }
107107
108- internal override SqlCase Clone ( SqlNodeCloneContext context )
109- {
110- if ( context . NodeMapping . TryGetValue ( this , out var v ) ) {
111- return ( SqlCase ) v ;
112- }
108+ internal override SqlCase Clone ( SqlNodeCloneContext context ) =>
109+ context . GetOrAdd ( this , static ( t , c ) => {
110+ var clone = new SqlCase ( t . value ? . Clone ( c ) ) ;
113111
114- var clone = new SqlCase ( value . IsNullReference ( ) ? null : value . Clone ( context ) ) ;
112+ if ( t . @else is not null )
113+ clone . Else = t . @else . Clone ( c ) ;
115114
116- if ( ! @else . IsNullReference ( ) )
117- clone . Else = @else . Clone ( context ) ;
115+ foreach ( KeyValuePair < SqlExpression , SqlExpression > pair in t . cases )
116+ clone [ pair . Key . Clone ( c ) ] = pair . Value . Clone ( c ) ;
118117
119- foreach ( KeyValuePair < SqlExpression , SqlExpression > pair in cases )
120- clone [ pair . Key . Clone ( context ) ] = pair . Value . Clone ( context ) ;
121-
122- context . NodeMapping [ this ] = clone ;
123- return clone ;
124- }
118+ return clone ;
119+ } ) ;
125120
126121 public override void AcceptVisitor ( ISqlVisitor visitor )
127122 {
Original file line number Diff line number Diff line change @@ -25,15 +25,9 @@ public override void ReplaceWith(SqlExpression expression)
2525 Text = replacingExpression . Text ;
2626 }
2727
28- internal override SqlComment Clone ( SqlNodeCloneContext context )
29- {
30- if ( context . NodeMapping . TryGetValue ( this , out var node ) )
31- return ( SqlComment ) node ;
32-
33- var clone = new SqlComment ( Text ) ;
34- context . NodeMapping [ this ] = clone ;
35- return clone ;
36- }
28+ internal override SqlComment Clone ( SqlNodeCloneContext context ) =>
29+ context . GetOrAdd ( this , static ( t , c ) =>
30+ new SqlComment ( t . Text ) ) ;
3731
3832 public override void AcceptVisitor ( ISqlVisitor visitor )
3933 {
Original file line number Diff line number Diff line change @@ -35,18 +35,13 @@ public override void ReplaceWith(SqlExpression expression)
3535 Arguments . Add ( argument ) ;
3636 }
3737
38- internal override SqlCustomFunctionCall Clone ( SqlNodeCloneContext context )
39- {
40- if ( context . NodeMapping . TryGetValue ( this , out var value ) ) {
41- return ( SqlCustomFunctionCall ) value ;
42- }
43-
44- var clone = new SqlCustomFunctionCall ( FunctionType ) ;
45- for ( int i = 0 , l = Arguments . Count ; i < l ; i ++ )
46- clone . Arguments . Add ( Arguments [ i ] . Clone ( context ) ) ;
47- context . NodeMapping [ this ] = clone ;
48- return clone ;
49- }
38+ internal override SqlCustomFunctionCall Clone ( SqlNodeCloneContext context ) =>
39+ context . GetOrAdd ( this , static ( t , c ) => {
40+ var clone = new SqlCustomFunctionCall ( t . FunctionType ) ;
41+ for ( int i = 0 , l = t . Arguments . Count ; i < l ; i ++ )
42+ clone . Arguments . Add ( t . Arguments [ i ] . Clone ( c ) ) ;
43+ return clone ;
44+ } ) ;
5045
5146 public override void AcceptVisitor ( ISqlVisitor visitor )
5247 {
Original file line number Diff line number Diff line change @@ -15,19 +15,15 @@ public class SqlDynamicFilter : SqlExpression
1515
1616 public List < SqlExpression > Expressions { get ; private set ; }
1717
18- internal override SqlDynamicFilter Clone ( SqlNodeCloneContext context )
19- {
20- if ( context . NodeMapping . TryGetValue ( this , out var value ) ) {
21- return ( SqlDynamicFilter ) value ;
22- }
23- var clone = new SqlDynamicFilter ( Id ) ;
24- foreach ( var expression in Expressions ) {
25- clone . Expressions . Add ( expression . Clone ( context ) ) ;
26- }
27-
28- context . NodeMapping [ this ] = clone ;
29- return clone ;
30- }
18+ internal override SqlDynamicFilter Clone ( SqlNodeCloneContext context ) =>
19+ context . GetOrAdd ( this , static ( t , c ) => {
20+ var clone = new SqlDynamicFilter ( t . Id ) ;
21+ foreach ( var expression in t . Expressions ) {
22+ clone . Expressions . Add ( expression . Clone ( c ) ) ;
23+ }
24+
25+ return clone ;
26+ } ) ;
3127
3228 public override void AcceptVisitor ( ISqlVisitor visitor )
3329 {
Original file line number Diff line number Diff line change @@ -33,18 +33,13 @@ public override void ReplaceWith(SqlExpression expression)
3333 Arguments . Add ( argument ) ;
3434 }
3535
36- internal override SqlFunctionCall Clone ( SqlNodeCloneContext context )
37- {
38- if ( context . NodeMapping . TryGetValue ( this , out var value ) ) {
39- return ( SqlFunctionCall ) value ;
40- }
41-
42- var clone = new SqlFunctionCall ( FunctionType ) ;
43- for ( int i = 0 , l = Arguments . Count ; i < l ; i ++ )
44- clone . Arguments . Add ( Arguments [ i ] . Clone ( context ) ) ;
45- context . NodeMapping [ this ] = clone ;
46- return clone ;
47- }
36+ internal override SqlFunctionCall Clone ( SqlNodeCloneContext context ) =>
37+ context . GetOrAdd ( this , static ( t , c ) => {
38+ var clone = new SqlFunctionCall ( t . FunctionType ) ;
39+ for ( int i = 0 , l = t . Arguments . Count ; i < l ; i ++ )
40+ clone . Arguments . Add ( t . Arguments [ i ] . Clone ( c ) ) ;
41+ return clone ;
42+ } ) ;
4843
4944 public override void AcceptVisitor ( ISqlVisitor visitor )
5045 {
Original file line number Diff line number Diff line change @@ -12,17 +12,13 @@ public class SqlRowNumber : SqlExpression
1212 {
1313 public SqlOrderCollection OrderBy { get ; private set ; }
1414
15- internal override SqlRowNumber Clone ( SqlNodeCloneContext context )
16- {
17- if ( context . NodeMapping . TryGetValue ( this , out var value ) ) {
18- return ( SqlRowNumber ) value ;
19- }
20- var clone = new SqlRowNumber ( ) ;
21- foreach ( SqlOrder so in OrderBy )
22- clone . OrderBy . Add ( ( SqlOrder ) so . Clone ( context ) ) ;
23- context . NodeMapping [ this ] = clone ;
24- return clone ;
25- }
15+ internal override SqlRowNumber Clone ( SqlNodeCloneContext context ) =>
16+ context . GetOrAdd ( this , static ( t , c ) => {
17+ var clone = new SqlRowNumber ( ) ;
18+ foreach ( SqlOrder so in t . OrderBy )
19+ clone . OrderBy . Add ( so . Clone ( c ) ) ;
20+ return clone ;
21+ } ) ;
2622
2723 public override void AcceptVisitor ( ISqlVisitor visitor )
2824 {
Original file line number Diff line number Diff line change @@ -33,22 +33,17 @@ public override void ReplaceWith(SqlExpression expression)
3333 query = replacingExpression . Query ;
3434 }
3535
36- internal override SqlSubQuery Clone ( SqlNodeCloneContext context )
37- {
38- if ( context . NodeMapping . TryGetValue ( this , out var value ) ) {
39- return ( SqlSubQuery ) value ;
40- }
41-
42- SqlSubQuery clone ;
43- SqlSelect select = query as SqlSelect ;
44- SqlQueryExpression expression = query as SqlQueryExpression ;
45- if ( select != null )
46- clone = new SqlSubQuery ( ( SqlSelect ) select . Clone ( context ) ) ;
47- else
48- clone = new SqlSubQuery ( ( SqlQueryExpression ) expression . Clone ( context ) ) ;
49- context . NodeMapping [ this ] = clone ;
50- return clone ;
51- }
36+ internal override SqlSubQuery Clone ( SqlNodeCloneContext context ) =>
37+ context . GetOrAdd ( this , static ( t , c ) => {
38+ SqlSubQuery clone ;
39+ SqlSelect select = t . query as SqlSelect ;
40+ SqlQueryExpression expression = t . query as SqlQueryExpression ;
41+ if ( select != null )
42+ clone = new SqlSubQuery ( select . Clone ( c ) ) ;
43+ else
44+ clone = new SqlSubQuery ( expression . Clone ( c ) ) ;
45+ return clone ;
46+ } ) ;
5247
5348 public override void AcceptVisitor ( ISqlVisitor visitor )
5449 {
Original file line number Diff line number Diff line change @@ -22,22 +22,17 @@ public override void ReplaceWith(SqlExpression expression)
2222 base . ReplaceWith ( expression ) ;
2323 }
2424
25- internal override SqlTableColumn Clone ( SqlNodeCloneContext context )
26- {
27- if ( context . NodeMapping . TryGetValue ( this , out var value ) ) {
28- return ( SqlTableColumn ) value ;
29- }
30-
31- var table = SqlTable ;
32- SqlNode clonedTable ;
33- if ( context . NodeMapping . TryGetValue ( SqlTable , out clonedTable ) ) {
34- table = ( SqlTable ) clonedTable ;
35- }
25+ internal override SqlTableColumn Clone ( SqlNodeCloneContext context ) =>
26+ context . GetOrAdd ( this , static ( t , c ) => {
27+ var table = t . SqlTable ;
28+ SqlNode clonedTable ;
29+ if ( c . NodeMapping . TryGetValue ( t . SqlTable , out clonedTable ) ) {
30+ table = ( SqlTable ) clonedTable ;
31+ }
3632
37- var clone = new SqlTableColumn ( table , Name ) ;
38- context . NodeMapping [ this ] = clone ;
39- return clone ;
40- }
33+ var clone = new SqlTableColumn ( table , t . Name ) ;
34+ return clone ;
35+ } ) ;
4136
4237 // Constructors
4338
Original file line number Diff line number Diff line change @@ -34,18 +34,13 @@ public override void ReplaceWith(SqlExpression expression)
3434 Arguments . Add ( argument ) ;
3535 }
3636
37- internal override SqlUserFunctionCall Clone ( SqlNodeCloneContext context )
38- {
39- if ( context . NodeMapping . TryGetValue ( this , out var value ) ) {
40- return ( SqlUserFunctionCall ) value ;
41- }
42-
43- SqlUserFunctionCall clone = new SqlUserFunctionCall ( name ) ;
44- for ( int i = 0 , l = Arguments . Count ; i < l ; i ++ )
45- clone . Arguments . Add ( Arguments [ i ] . Clone ( context ) ) ;
46- context . NodeMapping [ this ] = clone ;
47- return clone ;
48- }
37+ internal override SqlUserFunctionCall Clone ( SqlNodeCloneContext context ) =>
38+ context . GetOrAdd ( this , static ( t , c ) => {
39+ SqlUserFunctionCall clone = new SqlUserFunctionCall ( t . name ) ;
40+ for ( int i = 0 , l = t . Arguments . Count ; i < l ; i ++ )
41+ clone . Arguments . Add ( t . Arguments [ i ] . Clone ( c ) ) ;
42+ return clone ;
43+ } ) ;
4944
5045 internal SqlUserFunctionCall ( string name , IEnumerable < SqlExpression > arguments )
5146 : base ( SqlFunctionType . UserDefined , arguments )
Original file line number Diff line number Diff line change @@ -31,11 +31,10 @@ public class SqlOrder : SqlNode
3131 public bool Ascending { get ; private set ; }
3232
3333 internal override SqlOrder Clone ( SqlNodeCloneContext context ) =>
34- ( SqlOrder ) ( context . NodeMapping . TryGetValue ( this , out var clone )
35- ? clone
36- : context . NodeMapping [ this ] = ( Expression . IsNullReference ( )
37- ? new SqlOrder ( Position , Ascending )
38- : new SqlOrder ( Expression . Clone ( context ) , Ascending ) ) ) ;
34+ context . GetOrAdd ( this , static ( t , c ) =>
35+ t . Expression is null
36+ ? new SqlOrder ( t . Position , t . Ascending )
37+ : new SqlOrder ( t . Expression . Clone ( c ) , t . Ascending ) ) ;
3938
4039 public override void AcceptVisitor ( ISqlVisitor visitor )
4140 {
You can’t perform that action at this time.
0 commit comments