问题
I made an application, in which I need to define some local parameters. By local, I mean these parameters could be different for each user.
Until now I only used registry to save these parameters, using functions like that :
int ColAssComm = Register.getImportExcelDSTV("AssComm");
int ColAssDwg = Register.getImportExcelDSTV("AssDwg");
int ColAssGpe = Register.getImportExcelDSTV("AssGp");
int ColAssName = Register.getImportExcelDSTV("AssName");
...
Then I read/Write these parameters so :
public static void setImportExcelDSTV(string field, int valeur)
{
RegistryKey key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\\V-STEEL\\Config\\Imports\\Excel_DSTV");
key.SetValue(field, valeur);
key.Close();
}
public static int getImportExcelDSTV(string name)
{
int retour = 0;
RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\\V-STEEL\\Config\\Imports\\Excel_DSTV");
var maVariable = key.GetValue(name);
if (maVariable != null)
{
Int32.TryParse(maVariable.ToString(), out retour);
}
return retour;
}
Then I have been told that it would be better to use a xml file to save parameters, but I don't see the point? What advantages are there to use a file, rather registry?
回答1:
You can use an xml file just to make your deployment easier by having different xml files : staging-config.xml production-config.xml
But seems that you need to get different values for different logged in users as you are doing in "Microsoft.Win32.Registry.CurrentUser"
so it seems that what you are doing is fine as long as you figure out how to migrate and deploy these registry values.
来源:https://stackoverflow.com/questions/65148873/best-way-for-saving-local-parameters