CsWinRT icon indicating copy to clipboard operation
CsWinRT copied to clipboard

Proposal: Add option to exclude (obsolete) properties from GeneratedBindableCustomProperty

Open Marv51 opened this issue 9 months ago • 2 comments

Summary

When you add the [GeneratedBindableCustomProperty] the generator creates all the necessary code to make that class bindable when using AOT compilation.

I have a sample class that contains an obsolete property:

[WinRT.GeneratedBindableCustomProperty]
public class BlogPostViewModel{
     [Obsolete("Do not use this property")]
     public int BlogId => Random.Shared.Next();
}

The CsWinRT created code produces a warning (in the generated WinRTCustomBindableProperties.g.cs):

Warning CS0618: 'BlogPostViewModel.BlogId' is obsolete: 'Do not use this property'

Rationale

I think this warning is not helpful and should go away.

Currently I can include all other properties in the propertyNames property of the attribute to exclude the one obsolete property. This makes the warning go away, but requires me to keep a list of all properties (minus the obsolete one).

Important Notes

No response

Open Questions

I could imagine one of these 3 approaches:

  • suppress CS0618 for the generated code
  • add an "excludedPropertiesNames" option to the attribute and the generator to exclude individual properties
  • add an "exclude obsolete properties" option to the attribute and the generator

Marv51 avatar Feb 04 '25 08:02 Marv51