Allow hide parameterless struct ctor. #7968
Unanswered
nathan130200
asked this question in
Language Ideas
Replies: 2 comments 1 reply
-
In the absence of a public parameterless constructor, |
Beta Was this translation helpful? Give feedback.
1 reply
-
.NET runtime has employed an analyzer that prevents you to invoke But nothing can really prevent |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on a library where there are certain predefined actions, you invoke a function, pass which action and its parameters.
Could enums be used? Yes, of course, but to add metadata with attributes, it will be annoying as you have to do reflection or cache it somewhere.
So I had the idea of implementing readonly struct with the necessary data for each action. But then we came to a problem, for some bizarre reason, .NET or C# doesn't allow us to declare parameterless struct constructors as private...
And I can't understand why. I can't use
EditorBrowsable
to hide the constructor. It's an unpleasant and very irritating situation.Another example like in my xmpp library:
Would there be a possibility of allowing us to set the struct ctor private? Since there is no other way to declare enums with extra data. Without needing to use reflections, attributes or dictionary to map key/value of each enum.
In
IqType
example, i just used one field, but there's another example, that i must save also extra variable + one method for utility:Beta Was this translation helpful? Give feedback.
All reactions