Adjust casing of namof operator #9508
Replies: 4 comments 1 reply
-
I understand that making e.g. lowercase thing pascalcase might be too complex / undesirable. As such, maybe just limit the feature to simplifying casing and never adding diffCasing where it wasn't would be best. It might be tricky to communicate however. |
Beta Was this translation helpful? Give feedback.
-
Might be interesting to combine with #701 |
Beta Was this translation helpful? Give feedback.
-
That's not its name then, that's a different name. |
Beta Was this translation helpful? Give feedback.
-
C# language doesn't have the concept of character casing at all. For record parameters where doesn't matches the traditional naming convention, it still uses the originally specified string as constructor parameter name. As a speaker of language without casing concept, I strongly disagree to bake the concept of casing into programming language. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Nameof operator currently translates to a string that's exactly the same casing as the symbol it represents. This limits it's usability in cases where the name of the symbol is required, but slightly transformed. For example from PascalCase to camelCase in case of JSON properties or many telemetry scenarios.
My proposal is to extend
nameof(<symbol>)
to something akin tonameof(<symmbol>, <oneOfClosedSetOfCasingOptions>)
.The set of casings should be closed and there should not be support for arbitrary transformations (it'd be hard/impossible to lower anyway without runtime impact) to limit the risks of this feature.
The set of casings could be somewhat similar to: https://learn.microsoft.com/en-us/dotnet/api/system.text.json.jsonnamingpolicy?view=net-9.0 + PascalCase and lower and uppercase.
Useful for:
https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof
Beta Was this translation helpful? Give feedback.
All reactions