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
38 changes: 36 additions & 2 deletions src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,47 @@ public TestViewModel()
public static TestViewModel Instance { get; } = new();

/// <summary>
/// Gets or sets the test property.
/// Gets the internal test property. Should not prompt to replace with INPC Reactive Property.
/// </summary>
/// <value>
/// The test property.
/// </value>
[JsonInclude]
public string? TestProperty { get; set; } = "Test";
public string? TestInternalSetProperty { get; internal set; } = "Test";

/// <summary>
/// Gets the test private set property. Should not prompt to replace with INPC Reactive Property.
/// </summary>
/// <value>
/// The test private set property.
/// </value>
[JsonInclude]
public string? TestPrivateSetProperty { get; private set; } = "Test";

/// <summary>
/// Gets or sets the test automatic property.
/// </summary>
/// <value>
/// The test automatic property.
/// </value>
[JsonInclude]
public string? TestAutoProperty { get; set; } = "Test, should prompt to replace with INPC Reactive Property";

/// <summary>
/// Gets or sets the reactive command test property. Should not prompt to replace with INPC Reactive Property.
/// </summary>
/// <value>
/// The reactive command test property.
/// </value>
public ReactiveCommand<Unit, Unit>? ReactiveCommandTestProperty { get; set; }

/// <summary>
/// Gets or sets the reactive property test property. Should not prompt to replace with INPC Reactive Property.
/// </summary>
/// <value>
/// The reactive property test property.
/// </value>
public ReactiveProperty<int>? ReactivePropertyTestProperty { get; set; }

/// <summary>
/// Gets the can execute test1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,12 @@ private void AnalyzeNode(SyntaxNodeAnalysisContext context)
}

var isAutoProperty = propertyDeclaration.ExpressionBody == null && (propertyDeclaration.AccessorList?.Accessors.All(a => a.Body == null && a.ExpressionBody == null) != false);
var hasCorrectModifiers = propertyDeclaration.Modifiers.Any(SyntaxKind.PublicKeyword) && !propertyDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword);
var doesNotHavePrivateSetOrInternalSet = propertyDeclaration.AccessorList?.Accessors.Any(a => a.Modifiers.Any(SyntaxKind.PrivateKeyword) || a.Modifiers.Any(SyntaxKind.InternalKeyword)) == false;
var isNotReactiveCommand = !propertyDeclaration.Type.ToString().Contains("ReactiveCommand");
var isNotReactiveProperty = !propertyDeclaration.Type.ToString().Contains("ReactiveProperty");

if (isAutoProperty && propertyDeclaration.Modifiers.Any(SyntaxKind.PublicKeyword) && !propertyDeclaration.Modifiers.Any(SyntaxKind.StaticKeyword))
if (isAutoProperty && hasCorrectModifiers && doesNotHavePrivateSetOrInternalSet && isNotReactiveCommand && isNotReactiveProperty)
{
var diagnostic = Diagnostic.Create(DiagnosticDescriptors.PropertyToReactiveFieldRule, propertyDeclaration.GetLocation());
context.ReportDiagnostic(diagnostic);
Expand Down