nameof( ... )
reduces the number of magic strings that can easily be missed when renaming the member.
Looking through the framework reference source, I see another source of "magic strings",
That of resource keys / strings, which leads to potential issues when resources are renamed or removed.
Code that references them could be forgotten about,
In this area VB.net has some syntactic sugar around resource strings, that of My.Resources.
.
I think C# should also have some of this form of syntactic sugar also.
Possible solutions.
my.resources.
Resource file project items already generate type-safe classes in C#.
@HaloFour
It's not about making them but accessing them, in VB make is easier to access them and, use them.
``` VB.net
Module Module1
Sub Main()
' Resource exists
Dim A As String = My.Resources.ResourceManager.GetString("HelpText")
Dim B As String = My.Resources.HelpText
' Let's say we mis-type the key.
Dim C As String = My.Resources.ResourceManager.GetString("HelpTxt")
Dim D As String = My.Resources.HelpTxt
End Sub
End Module
As well has compile-time support for checking it the resource key exists.
Error Reported as compile-time
Severity: Error
Code: BC30456
Description: 'HelpText' is not a member of 'ConsoleApplication3.My.Resources'.
Project: ConsoleApplication3
File: ...ConsoleApplication3Module1.vb
Line: 9
Suppression: Active
```
The previous line Dim C As String = My.Resources.ResourceManager,GetString("HelpTxt")
is a valid compile.
@AdamSpeight2008
I know. I'm saying that Visual Studio already provides that same functionality for C# projects:
What it won't do is validate that a resource exists by String key, so MyResources.ResourceManager.GetString("HelpTxt")
would fail, just as it would in VB.NET.
What might be useful for both languages is an analyzer which could detect that the resource key specified by a String was missing and issue a warning.
Most helpful comment
@AdamSpeight2008
I know. I'm saying that Visual Studio already provides that same functionality for C# projects:
What it won't do is validate that a resource exists by String key, so
MyResources.ResourceManager.GetString("HelpTxt")
would fail, just as it would in VB.NET.What might be useful for both languages is an analyzer which could detect that the resource key specified by a String was missing and issue a warning.