Skip to content

[Bug] Ignore properties when binding with Options service #58384

@lonix1

Description

@lonix1

Is your feature request related to a problem? Please describe.

I'm using the Options service to bind hierarchical configuration data.

Suppose I have this class:

public class PersonOptions
{

  public string Name { get; set; }

  public int Age { get; set; }

  public bool Foo {                                // <--- I want binder to ignore this
    get {
      // ... do stuff
    }
  }

  public bool IgnoreMe => throw new Exception();   // <--- I want binder to ignore this

}

Because the Foo property is public, the binder runs it (which leads to various problems - why is it run?). My design requires it to be public, and I prefer not to change it to a method.

I hoped I could force the binder to ignore that property, e.g. using an attribute. I tried [JsonIgnore] but that didn't work.

Describe the solution you'd like

Please consider adding an attribute for this - if the property is decorated by that attribute, then don't try bind it, and don't run it.

Additional context

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions