Giter Club home page Giter Club logo

Comments (8)

AtomicBlom avatar AtomicBlom commented on July 28, 2024 1

Excellent, thank you for your assistance!

from conventional.

andrewabest avatar andrewabest commented on July 28, 2024

@AtomicBlom interesting! So your scenario is implying that the property needs to be explicitly marked public, so that the getters and setters can be public?

I can see a couple of options here:

  1. Modify the current convention to enforce the property level modifier. This is a reasonable path, but is a breaking behavioural change.
  2. Add an overload to the constructor of PropertiesMustHavePublic* that allows you to supply the binding flags you would like to work with. This is a non-breaking change, as we would leave the default behaviour as-is.
  3. Rename the current convention to PublicPropertiesMustHavePublicGetters and introduce an AllPropertiesMustHavePublicGetters convention. This is a breaking API change.

I'm partial to not making breaking changes on this convention, as it is one of the most widely used (Generally used to ensure contracts are serializable).

What are your thoughts on the above options?

from conventional.

AtomicBlom avatar AtomicBlom commented on July 28, 2024

I think that an overload would be completely fine, as I believe I've seen you modify the BindingFlags via a constructor parameter in another Specification, so that would certainly be consistent.

Our particular use case is that we have an assembly that defines the contracts used between services, and one of the things our unit tests were checking for is how usable the contract DTOs actually are. In my particular case, I had failed to mark a property as public, so even though it was passing the public getter and setter convention checks, when I pulled down the NuGet package to consume the contract, the property wasn't accessible as it was actually private, which was certainly not the behaviour I was expecting from the specification.

My expectation was that PropertiesMustHavePublicGetters meant that the property was publicly accessible, and a constructor would work nicely to create this expected behaviour.

from conventional.

andrewabest avatar andrewabest commented on July 28, 2024

@AtomicBlom I've realised that option 2 is still going to be a breaking change due to the way the API surfaces conventions as properties if they do not require input parameters.

Not a big problem, it should be easy enough for people upgrading to see what needs to change - they will just need to change .MustConformTo(Convention.PropertiesMustHavePublicGetters) to .MustConformTo(Convention.PropertiesMustHavePublicGetters()).

from conventional.

andrewabest avatar andrewabest commented on July 28, 2024

@AtomicBlom let me know if the PR addresses your use case.

I don't entirely love it, as there is some implicit behavior in the convention when supplied with the private BindingFlag - private properties are never going to have public gets and sets, so it feels a little odd to scoop them in to this convention.

However I think it is more useful than creating a convention per visibility modifier 👍

from conventional.

AtomicBlom avatar AtomicBlom commented on July 28, 2024

Well, the PR certainly addresses my use cause.

However, your comments are certainly reasonable. Perhaps then a better solution would be to have a dedicated specification .MustConformTo(Convention.PropertiesMustBePublic), or even using an Enum for the visibility .MustConformTo(Convention.PropertiesMustBe(Visibility.Public))

from conventional.

andrewabest avatar andrewabest commented on July 28, 2024

I certainly like .MustConformTo(Convention.PropertiesMustBePublic) more having stewed on it a little. Means a non-breaking change, and it is more explicit, and you can combine it with the other conventions to get the outcome you want. Going to close down that PR and start another 👍

from conventional.

andrewabest avatar andrewabest commented on July 28, 2024

I think I like that solution better @AtomicBlom - if you're happy here I'll merge it in once the build is green

from conventional.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.