Comments (8)
Excellent, thank you for your assistance!
from conventional.
@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:
- Modify the current convention to enforce the property level modifier. This is a reasonable path, but is a breaking behavioural change.
- 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. - Rename the current convention to
PublicPropertiesMustHavePublicGetters
and introduce anAllPropertiesMustHavePublicGetters
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.
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.
@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.
@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.
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.
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.
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)
- .NET Core / netstandard support HOT 1
- KnownPaths: Azure directory structure breaks DefaultSolutionRootFinder. HOT 1
- KnownPaths only works on Windows HOT 2
- MustHaveFilesBeX conventions do not detect files imported with a wildcards
- Add setup instructions for running tests locally. Database required? HOT 11
- Track releases in Github and add NuGet badge to README.md HOT 4
- PropertiesMustHavePrivateSetters convention passes for get-only properties HOT 6
- Async breaks MustNotResolveCurrentTimeViaDateTimeConventionSpecification HOT 5
- KnownPaths solution-root finding is broken on Linux/OSX HOT 1
- Dlls from transient / SDKs specification should disallow subdirectories under dotnet/packs HOT 5
- Expressions of Interest - MustConformToOneOf for conventions
- MustNotUseMethodSpecification could use MethodBase rather than MethodInfo HOT 1
- Github Actions + Containerize build process
- GetTypeDefinitionFor does not play nicely with runtime generated types (e.g. coverlet code coverage) HOT 9
- Reference to System.Data.SqlClient causes breakage on .NET 8
- Running built-in Roslyn analyzer fails build in Visual Studio 2022
- Proposed new conventions HOT 2
- Assembly (project) conventions should support Directory.Build.Props & Directory.Build.Targets HOT 6
- TryGetSemanticModel doesn't seem to resolve the semantic model correctly
- VoidMethodsMustNotBeAsync & AsyncMethodsMustHaveAsyncSuffix only consider public methods
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from conventional.