5
5
using System ;
6
6
using System . Collections . Immutable ;
7
7
using System . Linq ;
8
+ using CommunityToolkit . Mvvm . SourceGenerators . Helpers ;
8
9
using Microsoft . CodeAnalysis ;
9
10
using Microsoft . CodeAnalysis . CSharp ;
10
11
using Microsoft . CodeAnalysis . CSharp . Syntax ;
@@ -24,26 +25,12 @@ internal abstract partial record TypedConstantInfo
24
25
/// <returns>The <see cref="ExpressionSyntax"/> instance representing the current constant.</returns>
25
26
public abstract ExpressionSyntax GetSyntax ( ) ;
26
27
27
- /// <summary>
28
- /// Checks whether the current instance is the same as an input one.
29
- /// </summary>
30
- /// <param name="other">The <see cref="TypedConstantInfo"/> instance to compare to.</param>
31
- /// <returns>Whether or not the two instances are the same.</returns>
32
- /// <remarks>This method differs from <see cref="Equals(TypedConstantInfo?)"/> in that it checks for deep equality.</remarks>
33
- protected abstract bool IsEqualTo ( TypedConstantInfo other ) ;
34
-
35
- /// <summary>
36
- /// Adds the current instance to an incremental <see cref="HashCode"/> value.
37
- /// </summary>
38
- /// <param name="hashCode">The target <see cref="HashCode"/> value.</param>
39
- protected abstract void AddToHashCode ( ref HashCode hashCode ) ;
40
-
41
28
/// <summary>
42
29
/// A <see cref="TypedConstantInfo"/> type representing an array.
43
30
/// </summary>
44
31
/// <param name="ElementTypeName">The type name for array elements.</param>
45
32
/// <param name="Items">The sequence of contained elements.</param>
46
- public sealed record Array ( string ElementTypeName , ImmutableArray < TypedConstantInfo > Items ) : TypedConstantInfo
33
+ public sealed record Array ( string ElementTypeName , EquatableArray < TypedConstantInfo > Items ) : TypedConstantInfo
47
34
{
48
35
/// <inheritdoc/>
49
36
public override ExpressionSyntax GetSyntax ( )
@@ -55,38 +42,6 @@ public override ExpressionSyntax GetSyntax()
55
42
. WithInitializer ( InitializerExpression ( SyntaxKind . ArrayInitializerExpression )
56
43
. AddExpressions ( Items . Select ( static c => c . GetSyntax ( ) ) . ToArray ( ) ) ) ;
57
44
}
58
-
59
- /// <inheritdoc/>
60
- protected override bool IsEqualTo ( TypedConstantInfo other )
61
- {
62
- if ( other is Array array &&
63
- ElementTypeName == array . ElementTypeName &&
64
- Items . Length == array . Items . Length )
65
- {
66
- for ( int i = 0 ; i < Items . Length ; i ++ )
67
- {
68
- if ( ! Items [ i ] . IsEqualTo ( array . Items [ i ] ) )
69
- {
70
- return false ;
71
- }
72
- }
73
-
74
- return true ;
75
- }
76
-
77
- return false ;
78
- }
79
-
80
- /// <inheritdoc/>
81
- protected override void AddToHashCode ( ref HashCode hashCode )
82
- {
83
- hashCode . Add ( ElementTypeName ) ;
84
-
85
- foreach ( TypedConstantInfo item in Items )
86
- {
87
- item . AddToHashCode ( ref hashCode ) ;
88
- }
89
- }
90
45
}
91
46
92
47
/// <summary>
@@ -105,20 +60,6 @@ public override ExpressionSyntax GetSyntax()
105
60
{
106
61
return LiteralExpression ( SyntaxKind . StringLiteralExpression , Literal ( Value ) ) ;
107
62
}
108
-
109
- /// <inheritdoc/>
110
- protected override bool IsEqualTo ( TypedConstantInfo other )
111
- {
112
- return
113
- other is String @string &&
114
- Value == @string . Value ;
115
- }
116
-
117
- /// <inheritdoc/>
118
- protected override void AddToHashCode ( ref HashCode hashCode )
119
- {
120
- hashCode . Add ( Value ) ;
121
- }
122
63
}
123
64
124
65
/// <summary>
@@ -132,20 +73,6 @@ public override ExpressionSyntax GetSyntax()
132
73
{
133
74
return LiteralExpression ( Value ? SyntaxKind . TrueLiteralExpression : SyntaxKind . FalseLiteralExpression ) ;
134
75
}
135
-
136
- /// <inheritdoc/>
137
- protected override bool IsEqualTo ( TypedConstantInfo other )
138
- {
139
- return
140
- other is Boolean @bool &&
141
- Value == @bool . Value ;
142
- }
143
-
144
- /// <inheritdoc/>
145
- protected override void AddToHashCode ( ref HashCode hashCode )
146
- {
147
- hashCode . Add ( Value ) ;
148
- }
149
76
}
150
77
151
78
/// <summary>
@@ -175,20 +102,6 @@ public override ExpressionSyntax GetSyntax()
175
102
_ => throw new ArgumentException ( "Invalid primitive type" )
176
103
} ) ;
177
104
}
178
-
179
- /// <inheritdoc/>
180
- protected override bool IsEqualTo ( TypedConstantInfo other )
181
- {
182
- return
183
- other is Of < T > box &&
184
- Value . Equals ( box . Value ) ;
185
- }
186
-
187
- /// <inheritdoc/>
188
- protected override void AddToHashCode ( ref HashCode hashCode )
189
- {
190
- hashCode . Add ( Value ) ;
191
- }
192
105
}
193
106
}
194
107
@@ -203,20 +116,6 @@ public override ExpressionSyntax GetSyntax()
203
116
{
204
117
return TypeOfExpression ( IdentifierName ( TypeName ) ) ;
205
118
}
206
-
207
- /// <inheritdoc/>
208
- protected override bool IsEqualTo ( TypedConstantInfo other )
209
- {
210
- return
211
- other is Type type &&
212
- TypeName == type . TypeName ;
213
- }
214
-
215
- /// <inheritdoc/>
216
- protected override void AddToHashCode ( ref HashCode hashCode )
217
- {
218
- hashCode . Add ( TypeName ) ;
219
- }
220
119
}
221
120
222
121
/// <summary>
@@ -234,22 +133,6 @@ public override ExpressionSyntax GetSyntax()
234
133
IdentifierName ( TypeName ) ,
235
134
LiteralExpression ( SyntaxKind . NumericLiteralExpression , ParseToken ( Value . ToString ( ) ) ) ) ;
236
135
}
237
-
238
- /// <inheritdoc/>
239
- protected override bool IsEqualTo ( TypedConstantInfo other )
240
- {
241
- return
242
- other is Enum @enum &&
243
- TypeName == @enum . TypeName &&
244
- Value . Equals ( @enum . Value ) ;
245
- }
246
-
247
- /// <inheritdoc/>
248
- protected override void AddToHashCode ( ref HashCode hashCode )
249
- {
250
- hashCode . Add ( TypeName ) ;
251
- hashCode . Add ( Value ) ;
252
- }
253
136
}
254
137
255
138
/// <summary>
@@ -262,17 +145,5 @@ public override ExpressionSyntax GetSyntax()
262
145
{
263
146
return LiteralExpression ( SyntaxKind . NullLiteralExpression ) ;
264
147
}
265
-
266
- /// <inheritdoc/>
267
- protected override bool IsEqualTo ( TypedConstantInfo other )
268
- {
269
- return other is Null ;
270
- }
271
-
272
- /// <inheritdoc/>
273
- protected override void AddToHashCode ( ref HashCode hashCode )
274
- {
275
- hashCode . Add ( ( object ? ) null ) ;
276
- }
277
148
}
278
149
}
0 commit comments