So my main issue was I had a static class in a VB.NET project that I used for accessing AppSettings. Original Code looks like this
Module AppSettings
Public Property Value(ByVal NodeName As String) As String
Get
ConfigurationManager.RefreshSection("appSettings")
Return ConfigurationManager.AppSettings(NodeName)
End Get
Set(ByVal value As String)
Dim Config As Configuration = _
ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location)
Config.AppSettings.Settings.Item(NodeName).Value = value
Config.AppSettings.SectionInformation.ForceSave = True
Config.Save(ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")
End Set
End Property
End Module
so after a lot of searching I decided that that using an indexer was the way to go I came up with the following c# code and causes no *compiling errors unless I try to implement it. I don't know if the issue is with my implementation or syntax when I'm trying to use it.
public static class AppSettings
{
public static class Value
{
public static string this[string nodeName]
{
get
{
ConfigurationManager.RefreshSection("appSettings");
return ConfigurationManager.AppSettings[nodeName];
}
set
{
Configuration Config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
Config.AppSettings.Settings[nodeName].Value = value;
Config.AppSettings.SectionInformation.ForceSave = true;
Config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
}
}
}
this is the code that shows the error when I try to use these new classes
string mySetting = AppSettings.Value["mySettingName"];
this gives me the following error
'...AppSettings.Value' is a 'type', which is not valid in the given context
any help would be greatly appreciated.
Edit after some helpful comments I realized the code does not compile, for some reason was not showing me an error. So my is how would be the most similar way to the working VB code to implement it in C#.