Skip to content

Suppress CSLA0007 analyzer in AutoImplementProperties generated code#4756

Merged
rockfordlhotka merged 5 commits into
mainfrom
copilot/fix-csla0007-analyzer-issue
Oct 28, 2025
Merged

Suppress CSLA0007 analyzer in AutoImplementProperties generated code#4756
rockfordlhotka merged 5 commits into
mainfrom
copilot/fix-csla0007-analyzer-issue

Conversation

Copilot AI commented Oct 28, 2025

Copy link
Copy Markdown
Contributor

The AutoImplementProperties source generator emits code that triggers CSLA0007 ("Properties that use managed backing fields should only use Get/Set/Read/Load methods"). Since the analyzer exists to guide human developers, not generated code, suppress it in generated files.

Changes

  • SerializationPartialBuilder.cs: Emit #pragma warning disable CSLA0007 after //<auto-generated/> and #pragma warning restore CSLA0007 at end of generated files
  • Test snapshots: Updated 68 verified snapshot files to reflect new output format

Generated Output

Before:

//<auto-generated/>
#nullable enable
using System;
using Csla;

namespace Test;

public partial class PersonEdit
{
    public static readonly PropertyInfo<string> NameProperty = RegisterProperty<string>(nameof(Name));
    public partial string Name
    {
        get => GetProperty(NameProperty)!;
        private set => SetProperty(NameProperty, value);
    }
}

After:

//<auto-generated/>
#pragma warning disable CSLA0007
#nullable enable
using System;
using Csla;

namespace Test;

public partial class PersonEdit
{
    public static readonly PropertyInfo<string> NameProperty = RegisterProperty<string>(nameof(Name));
    public partial string Name
    {
        get => GetProperty(NameProperty)!;
        private set => SetProperty(NameProperty, value);
    }
}
#pragma warning restore CSLA0007
Original prompt

This section details on the original issue you should resolve

<issue_title>AutoImplementProperties generator is triggering CSLA0007 analyzer</issue_title>
<issue_description>The AutoImplementProperties generator is creating some implementation code that is triggering the CSLA0007 analyzer. This needs to be reconciled - either the generator or analyzer is wrong.

    S:\src\rdl\csla\Samples\BlazorExample\BlazorExample\BusinessLibrary\obj\Debug\net9.0\generated\Csla.Generator.AutoImplementProperties.CSharp\Csla.Generator.AutoImplementProperties.CSharp.AutoImplement.IncrementalAutoImplementPropertiesPartialsGenerator\PersonEdit.g.cs(13,7): warning CSLA0007: Properties that use managed backing fields should only use Get/Set/Read/Load methods and nothing else (https://github.com/MarimerLLC/csla/tree/main/docs/analyzers/CSLA0007-EvaluatePropertiesForSimplicityAnalyzer.md)

Thinking about this further, I think we don't care if the generator conforms exactly to the needs of the analyzer. The analyzer exists to help human developers.

The solution is to suppress the analyzer in the generated code file.

This means updating the Csla.Generator.AutoImplementProperties generator so when it creates the partial class with the property implementations, it should suppress CSLA0007 for that file without affecting any other files.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@rockfordlhotka rockfordlhotka marked this pull request as ready for review October 28, 2025 22:00
Copilot AI changed the title [WIP] Fix AutoImplementProperties generator triggering CSLA0007 analyzer Suppress CSLA0007 analyzer in AutoImplementProperties generated code Oct 28, 2025
Copilot AI requested a review from rockfordlhotka October 28, 2025 22:10
@rockfordlhotka rockfordlhotka merged commit b497236 into main Oct 28, 2025
2 checks passed
@rockfordlhotka rockfordlhotka deleted the copilot/fix-csla0007-analyzer-issue branch October 28, 2025 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AutoImplementProperties generator is triggering CSLA0007 analyzer

2 participants