Skip to content

Commit 8c03ffa

Browse files
committed
Fix NullabilityAttributesGenerator generation conditions
1 parent 8fba78d commit 8c03ffa

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

CommunityToolkit.Mvvm.SourceGenerators/Attributes/NullabilityAttributesGenerator.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,31 @@ public sealed class NullabilityAttributesGenerator : IIncrementalGenerator
2929
/// <inheritdoc/>
3030
public void Initialize(IncrementalGeneratorInitializationContext context)
3131
{
32-
// Check that the target attributes are not available in the consuming project. To ensure that
33-
// this works fine both in .NET (Core) and .NET Standard implementations, we also need to check
34-
// that the target types are declared as public (we assume that in this case those types are from the BCL).
32+
// Check that the target attributes are not available in the consuming project. To ensure that this
33+
// works fine both in .NET (Core) and .NET Standard implementations, we also need to check that the
34+
// target types are declared as public (we assume that in this case those types are from the BCL).
3535
// This avoids issues on .NET Standard with Roslyn also seeing internal types from referenced assemblies.
3636

37-
// Check whether [NotNull] is available
38-
IncrementalValueProvider<bool> isNotNullAttributeAvailable =
37+
// Check whether [NotNull] is not available
38+
IncrementalValueProvider<bool> isNotNullAttributeNotAvailable =
3939
context.CompilationProvider
40-
.Select(static (item, _) => item.HasAccessibleTypeWithMetadataName(NotNullAttributeMetadataName));
40+
.Select(static (item, _) => !item.HasAccessibleTypeWithMetadataName(NotNullAttributeMetadataName));
4141

4242
// Generate the [NotNull] type
43-
context.RegisterConditionalSourceOutput(isNotNullAttributeAvailable, static context =>
43+
context.RegisterConditionalSourceOutput(isNotNullAttributeNotAvailable, static context =>
4444
{
4545
string source = LoadAttributeSourceWithMetadataName(NotNullAttributeMetadataName);
4646

4747
context.AddSource(NotNullAttributeMetadataName, source);
4848
});
4949

50-
// Check whether [NotNullIfNotNull] is available
51-
IncrementalValueProvider<bool> isNotNullIfNotNullAttributeAvailable =
50+
// Check whether [NotNullIfNotNull] is not available
51+
IncrementalValueProvider<bool> isNotNullIfNotNullAttributeNotAvailable =
5252
context.CompilationProvider
53-
.Select(static (item, _) => item.HasAccessibleTypeWithMetadataName(NotNullIfNotNullAttributeMetadataName));
53+
.Select(static (item, _) => !item.HasAccessibleTypeWithMetadataName(NotNullIfNotNullAttributeMetadataName));
5454

5555
// Generate the [NotNullIfNotNull] type
56-
context.RegisterConditionalSourceOutput(isNotNullIfNotNullAttributeAvailable, static context =>
56+
context.RegisterConditionalSourceOutput(isNotNullIfNotNullAttributeNotAvailable, static context =>
5757
{
5858
string source = LoadAttributeSourceWithMetadataName(NotNullIfNotNullAttributeMetadataName);
5959

0 commit comments

Comments
 (0)