Skip to content

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

@Marv51

Description

@Marv51

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions