Best way for saving local parameters [closed]

一个人想着一个人 提交于 2020-12-07 06:42:08

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!