diegofrata / Generator.Equals

A source code generator for automatically implementing IEquatable<T> using only attributes.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Suppress obsolete warnings in generated code

fjmorel opened this issue · comments

Issue
When I mark a property as obsolete but don't use [IgnoreEquality], then I get build warnings about usages of the obsolete property.

I would expect those to be suppressed because they will go away when the property is removed anyway. In the meantime, I can't use [Obsolete] on properties in projects where I treat warnings as errors.

Solution 1
Use a pragma to suppress build warnings when comparing obsolete things in the generated source.

Solution 2
Add a toggle on [Equatable] to decide whether to use a pragma to suppress obsolete warnings. Something like:

[Equatable(SuppressObsoleteWarnings = true)]
public partial record Something
{
  public string Thing1 { get; set; }
  [Obsolete]
  public string Thing2 { get; set; }
}

If you have a preferred way of doing it, I'd be more than happy to write up a PR.