missing: constructor visibility modifier
Posted: Tue 03 Jan 2012 21:57
I can control the modifier of a Class, but it appears there is no way to control the modifier on the auto-implemented constructor?
I have many cases where the type itself is public or internal, but access to the auto-generated zero-argument constructor needs to be restricted.
There are many common cases where constructing a valid instance of a given type is impossible without a particular argument; for example, cases where some type of child-object is not valid without specifying the owner-object.
Taking a literal example, let's say we have types Door and House. We don't want Doors in our model (or database) that don't reference the House they're attached to - in this case, the generated zero-argument public constructor poses a problem, since it enables you to construct instances of Door that violate this constraint; the constructor must be made private, and I must implement a public Door constructor that requires a House argument.
I could certainly add this feature myself, but it seems like it's going to be a common requirements. Any chance you plan on adding that feature?
I have many cases where the type itself is public or internal, but access to the auto-generated zero-argument constructor needs to be restricted.
There are many common cases where constructing a valid instance of a given type is impossible without a particular argument; for example, cases where some type of child-object is not valid without specifying the owner-object.
Taking a literal example, let's say we have types Door and House. We don't want Doors in our model (or database) that don't reference the House they're attached to - in this case, the generated zero-argument public constructor poses a problem, since it enables you to construct instances of Door that violate this constraint; the constructor must be made private, and I must implement a public Door constructor that requires a House argument.
I could certainly add this feature myself, but it seems like it's going to be a common requirements. Any chance you plan on adding that feature?