Monodroid:我应该把配置设置放在哪里? [英] Monodroid: Where should I put configuration settings?
问题描述
从 Miguel de Icaza :
我们使用更适合移动设备的库配置文件,因此我们删除了不需要的功能(像整个System.Configuration堆栈,就像Silverlight一样)。
We use a library profile that is better suited for mobile devices, so we removed features that are not necessary (like the entire System.Configuration stack, just like Silverlight does).
经过多年的.NET开发,我已经习惯于将配置设置存储在 web.config
和 app.config
文件。
After years of .NET development, I'm accustomed to storing configuration settings in web.config
and app.config
files.
- 我把我的配置设置?
- 如果重要,我也想为不同的构建配置存储不同的配置设置。
推荐答案
我可能会建议使用共享首选项和编译符号来管理不同的配置。以下是如何使用首选项文件根据编译符号添加或更改键的示例。此外,您可以创建一个单独的首选项文件,该文件仅适用于特定配置。因为这些键在所有配置上都不可用,请务必在使用前对其进行检查。
I would probably recommend using shared preferences and compilation symbols to manage different configurations. Below is an example of how you can use a preferences file to add or change keys based on the compilation symbols. Additionally, you could create a separate preferences file that is only available for a particular configuration. Because these keys are not available on all configurations, make sure to always perform checks for them before using.
var prefs = this.GetSharedPreferences("Config File Name", FileCreationMode.Private); var editor = prefs.Edit(); #if MonoRelease editor.PutString("MyKey", "My Release Value"); editor.PutString("ReleaseKey", "My Release Value"); #else editor.PutString("MyKey", "My Debug Value"); editor.PutString("DebugKey", "My Debug Value"); #endif editor.PutString("CommonKey", "Common Value"); editor.Commit();
这篇关于Monodroid:我应该把配置设置放在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!