@@ -16,8 +16,7 @@ namespace Xtensive.Linq
16
16
/// that can be used for comparing expression trees and calculating their hash codes.
17
17
/// </summary>
18
18
[ DebuggerDisplay ( "{expression}" ) ]
19
- public sealed class ExpressionTree
20
- : IEquatable < ExpressionTree >
19
+ public readonly struct ExpressionTree : IEquatable < ExpressionTree >
21
20
{
22
21
private readonly int hashCode ;
23
22
private readonly Expression expression ;
@@ -26,38 +25,21 @@ public sealed class ExpressionTree
26
25
/// Gets the underlying <see cref="Expression"/>.
27
26
/// </summary>
28
27
/// <returns></returns>
29
- public Expression ToExpression ( )
30
- {
31
- return expression ;
32
- }
33
-
28
+ public Expression ToExpression ( ) => expression ;
29
+
34
30
#region ToString, GetHashCode, Equals, ==, != implementation
35
31
36
32
/// <inheritdoc/>
37
- public override string ToString ( )
38
- {
39
- return expression . ToString ( true ) ;
40
- }
33
+ public override string ToString ( ) => expression . ToString ( true ) ;
41
34
42
35
/// <inheritdoc/>
43
- public override int GetHashCode ( )
44
- {
45
- return hashCode ;
46
- }
36
+ public override int GetHashCode ( ) => hashCode ;
47
37
48
38
/// <inheritdoc/>
49
- public override bool Equals ( object obj )
50
- {
51
- return Equals ( obj as ExpressionTree ) ;
52
- }
39
+ public bool Equals ( ExpressionTree other ) => new ExpressionComparer ( ) . AreEqual ( expression , other . expression ) ;
53
40
54
41
/// <inheritdoc/>
55
- public bool Equals ( ExpressionTree other )
56
- {
57
- if ( ReferenceEquals ( other , null ) )
58
- return false ;
59
- return new ExpressionComparer ( ) . AreEqual ( expression , other . expression ) ;
60
- }
42
+ public override bool Equals ( object obj ) => obj is ExpressionTree other && Equals ( other ) ;
61
43
62
44
/// <summary>
63
45
/// Implements the operator ==.
@@ -67,11 +49,8 @@ public bool Equals(ExpressionTree other)
67
49
/// <returns><see langword="true"/> if <paramref name="left"/> is equal to <paramref name="right"/>.
68
50
/// Otherwise, <see langword="false"/>.
69
51
/// </returns>
70
- public static bool operator == ( ExpressionTree left , ExpressionTree right )
71
- {
72
- return Equals ( left , right ) ;
73
- }
74
-
52
+ public static bool operator == ( ExpressionTree left , ExpressionTree right ) => Equals ( left , right ) ;
53
+
75
54
/// <summary>
76
55
/// Implements the operator !=.
77
56
/// </summary>
@@ -80,10 +59,7 @@ public bool Equals(ExpressionTree other)
80
59
/// <returns><see langword="true"/> if <paramref name="left"/> is not equal to <paramref name="right"/>.
81
60
/// Otherwise, <see langword="false"/>.
82
61
/// </returns>
83
- public static bool operator != ( ExpressionTree left , ExpressionTree right )
84
- {
85
- return ! Equals ( left , right ) ;
86
- }
62
+ public static bool operator != ( ExpressionTree left , ExpressionTree right ) => ! Equals ( left , right ) ;
87
63
88
64
#endregion
89
65
@@ -94,29 +70,22 @@ public bool Equals(ExpressionTree other)
94
70
/// <param name="right">Second expression to compare.</param>
95
71
/// <returns>true, if <paramref name="left"/> and <paramref name="right"/>
96
72
/// are equal by value, otherwise false.</returns>
97
- public static bool Equals ( Expression left , Expression right )
98
- {
99
- return new ExpressionComparer ( ) . AreEqual ( left , right ) ;
100
- }
73
+ public static bool Equals ( Expression left , Expression right ) => new ExpressionComparer ( ) . AreEqual ( left , right ) ;
101
74
102
75
/// <summary>
103
76
/// Calculates hash code by value for the specified <paramref name="expression"/>.
104
77
/// </summary>
105
78
/// <param name="expression">Expression to calculate hash code for.</param>
106
79
/// <returns>Hash code for <paramref name="expression"/>.</returns>
107
- public static int GetHashCode ( Expression expression )
108
- {
109
- return new ExpressionHashCodeCalculator ( ) . CalculateHashCode ( expression ) ;
110
- }
80
+ public static int GetHashCode ( Expression expression ) => new ExpressionHashCodeCalculator ( ) . CalculateHashCode ( expression ) ;
111
81
112
82
113
83
// Constructors
114
84
115
85
internal ExpressionTree ( Expression expression )
116
86
{
117
- ArgumentValidator . EnsureArgumentNotNull ( expression , "expression" ) ;
118
87
this . expression = expression ;
119
88
hashCode = new ExpressionHashCodeCalculator ( ) . CalculateHashCode ( expression ) ;
120
89
}
121
90
}
122
- }
91
+ }
0 commit comments