4
4
5
5
using System . Collections . Immutable ;
6
6
using System . ComponentModel ;
7
+ using System . Diagnostics . CodeAnalysis ;
7
8
using System . Globalization ;
8
9
using System . Linq ;
9
10
using System . Threading ;
@@ -33,13 +34,15 @@ internal static class Execute
33
34
/// <param name="fieldSymbol">The input <see cref="IFieldSymbol"/> instance to process.</param>
34
35
/// <param name="semanticModel">The <see cref="SemanticModel"/> instance for the current run.</param>
35
36
/// <param name="token">The cancellation token for the current operation.</param>
37
+ /// <param name="propertyInfo">The resulting <see cref="PropertyInfo"/> value, if successfully retrieved.</param>
36
38
/// <param name="diagnostics">The resulting diagnostics from the processing operation.</param>
37
39
/// <returns>The resulting <see cref="PropertyInfo"/> instance for <paramref name="fieldSymbol"/>, if successful.</returns>
38
- public static PropertyInfo ? TryGetInfo (
40
+ public static bool TryGetInfo (
39
41
FieldDeclarationSyntax fieldSyntax ,
40
42
IFieldSymbol fieldSymbol ,
41
43
SemanticModel semanticModel ,
42
44
CancellationToken token ,
45
+ [ NotNullWhen ( true ) ] out PropertyInfo ? propertyInfo ,
43
46
out ImmutableArray < Diagnostic > diagnostics )
44
47
{
45
48
ImmutableArray < Diagnostic > . Builder builder = ImmutableArray . CreateBuilder < Diagnostic > ( ) ;
@@ -53,9 +56,10 @@ internal static class Execute
53
56
fieldSymbol . ContainingType ,
54
57
fieldSymbol . Name ) ;
55
58
59
+ propertyInfo = null ;
56
60
diagnostics = builder . ToImmutable ( ) ;
57
61
58
- return null ;
62
+ return false ;
59
63
}
60
64
61
65
// Get the property type and name
@@ -72,12 +76,13 @@ internal static class Execute
72
76
fieldSymbol . ContainingType ,
73
77
fieldSymbol . Name ) ;
74
78
79
+ propertyInfo = null ;
75
80
diagnostics = builder . ToImmutable ( ) ;
76
81
77
82
// If the generated property would collide, skip generating it entirely. This makes sure that
78
83
// users only get the helpful diagnostic about the collision, and not the normal compiler error
79
84
// about a definition for "Property" already existing on the target type, which might be confusing.
80
- return null ;
85
+ return false ;
81
86
}
82
87
83
88
// Check for special cases that are explicitly not allowed
@@ -89,9 +94,10 @@ internal static class Execute
89
94
fieldSymbol . ContainingType ,
90
95
fieldSymbol . Name ) ;
91
96
97
+ propertyInfo = null ;
92
98
diagnostics = builder . ToImmutable ( ) ;
93
99
94
- return null ;
100
+ return false ;
95
101
}
96
102
97
103
ImmutableArray < string > . Builder propertyChangedNames = ImmutableArray . CreateBuilder < string > ( ) ;
@@ -238,9 +244,7 @@ internal static class Execute
238
244
fieldSymbol . Name ) ;
239
245
}
240
246
241
- diagnostics = builder . ToImmutable ( ) ;
242
-
243
- return new (
247
+ propertyInfo = new PropertyInfo (
244
248
typeNameWithNullabilityAnnotations ,
245
249
fieldName ,
246
250
propertyName ,
@@ -250,6 +254,10 @@ internal static class Execute
250
254
notifyRecipients ,
251
255
notifyDataErrorInfo ,
252
256
forwardedAttributes . ToImmutable ( ) ) ;
257
+
258
+ diagnostics = builder . ToImmutable ( ) ;
259
+
260
+ return true ;
253
261
}
254
262
255
263
/// <summary>
0 commit comments