Replies: 6 comments
-
call |
Beta Was this translation helpful? Give feedback.
-
Well, then it's just as easy creating a constant |
Beta Was this translation helpful? Give feedback.
-
very nice proposal, only upvoted because of proposed enum part. ( |
Beta Was this translation helpful? Give feedback.
-
I don't think |
Beta Was this translation helpful? Give feedback.
-
@svick exactly, but |
Beta Was this translation helpful? Give feedback.
-
To me, this falls under the buckets of:
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
In lots of code today, magic strings are used to in different scenarios. The
nameof
keyword greatly decreased the number of magic strings usages, simplified usage and reduced typos issues.The
nameof
keyword also made it possible to create constant string definitions of the constant name which also is a lot of help. Constants are normally written like this:However, I think writing constant string definitions like the above example is cumbersome, and I think that introducing a new keyword
define
constant definitions could be done in an easier format:Which internally should transform to a const string as defined in the previous const example.
The default access modifier for the
define
keyword should be the same asconst
.An other option is to (as other has suggested) extending
enum
. The latter example is already covered by other issues, but the first would be nice that could be defined something like:But I think that the latter will force developers to create unneccessary enums, especially in situations you only need a simple constant string within a class definition.
I think that this would ease a lot of const definitions for developers around the magic string issue.
Beta Was this translation helpful? Give feedback.
All reactions