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 @@ -249,8 +249,12 @@ public override void Initialize(AnalysisContext context)
}

// Check that either of them is a semicolon token 'get;' accessor (it can be in either position)
if (firstAccessor.IsKind(SyntaxKind.GetAccessorDeclaration) && firstAccessor.SemicolonToken.IsKind(SyntaxKind.SemicolonToken) ||
secondAccessor.IsKind(SyntaxKind.GetAccessorDeclaration) && secondAccessor.SemicolonToken.IsKind(SyntaxKind.SemicolonToken))
if (firstAccessor.IsKind(SyntaxKind.GetAccessorDeclaration) &&
firstAccessor.SemicolonToken.IsKind(SyntaxKind.SemicolonToken) &&
firstAccessor.ExpressionBody is null ||
secondAccessor.IsKind(SyntaxKind.GetAccessorDeclaration) &&
secondAccessor.SemicolonToken.IsKind(SyntaxKind.SemicolonToken) &&
secondAccessor.ExpressionBody is null)
{
validFlags[0] = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1403,6 +1403,27 @@ public string Name
await CSharpAnalyzerWithLanguageVersionTest<UseObservablePropertyOnSemiAutoPropertyAnalyzer>.VerifyAnalyzerAsync(source, LanguageVersion.Preview);
}

[TestMethod]
public async Task UseObservablePropertyOnSemiAutoPropertyAnalyzer_GetAccessorWithExpressionBody_DoesNotWarn()
{
const string source = """
using CommunityToolkit.Mvvm.ComponentModel;

namespace MyApp;

public partial class SampleViewModel : ObservableObject
{
public string Name
{
get => "Hello world";
set => SetProperty(ref field, value);
}
}
""";

await CSharpAnalyzerWithLanguageVersionTest<UseObservablePropertyOnSemiAutoPropertyAnalyzer>.VerifyAnalyzerAsync(source, LanguageVersion.Preview);
}

[TestMethod]
public async Task UseObservablePropertyOnSemiAutoPropertyAnalyzer_ValidProperty_Warns()
{
Expand Down