Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public override async Task RegisterCodeFixesAsync(CodeFixContext context)

var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false);

if (semanticModel.Compilation.GetBestTypeByMetadataName("System.Runtime.CompilerServices.RequiredMemberAttribute") is null)
{
// The attribute necessary to support required members is not present
return;
}

var fieldOrPropertySymbol = semanticModel.GetDeclaredSymbol(node, cancellationToken);
if (fieldOrPropertySymbol is IPropertySymbol propertySymbol)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.CodeAnalysis.Editor.UnitTests.CodeActions;
using Microsoft.CodeAnalysis.Test.Utilities;
using Microsoft.CodeAnalysis.Testing;
using Roslyn.Test.Utilities;
using Xunit;

namespace Microsoft.CodeAnalysis.CSharp.Analyzers.UnitTests.MakeMemberRequired
Expand Down Expand Up @@ -119,6 +120,28 @@ public static IEnumerable<object[]> AccessorAccessibilityModifierCombinationsWhe
yield return new[] { "internal", "private protected" };
}

[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/68478")]
Comment on lines +123 to +124
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[Fact]
[WorkItem("https://github.com/dotnet/roslyn/issues/68478")]
[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/68478")]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ Keeping this one as-is

public async Task SimpleSetPropertyMissingRequiredAttribute()
{
var code =
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my preference would also be consistency. but it's not a deal breaker.

#nullable enable
class MyClass
{
public string {|CS8618:MyProperty|} { get; set; }
}
""";

await new VerifyCS.Test
{
TestCode = code,
FixedCode = code,
LanguageVersion = LanguageVersion.CSharp11,
ReferenceAssemblies = ReferenceAssemblies.Net.Net60,
}.RunAsync();
}

[Fact]
public async Task SimpleSetProperty()
{
Expand Down