mono - 在 monodroid 或 monotouch 中,我应该使用什么代替 app.config 来配置字符串?

标签 mono xamarin.ios xamarin.android app-config

我想在 monodroid 项目中存储开发与生产连接字符串和配置字符串。我通常会将它作为应用程序设置存储在 web.config 或 app.config 中,但是我应该如何在 monodroid 和 monotouch 项目中做到这一点?我还希望它在调试和发布版本之间自动切换配置,就像 Visual Studio 对 *.config 文件所做的那样。在 iOS 应用程序中,我可以将这些存储在 plist 中,但我想要单声道的跨平台解决方案。

我将如何在 monodroid 或 monotouch 中做到这一点?

最佳答案

您应该只使用带有 #if 的静态类声明。

就像是:

public static class Configuration {
#if DEBUG
    public const string ConnectionString = "debug string";
#else
    public const string ConnectionString = "release string";
#endif
}

使用的好处 app.config是无需重新编译即可更改文件系统上的这些设置的能力。在移动设备上,没有一个好的方法(尤其是在 iOS 上)在部署后编辑文件。因此,通常最好只使用静态类并在需要更改值时重新部署。这也适用于所有平台,因为它只是 C# 代码在做这项工作。

关于mono - 在 monodroid 或 monotouch 中,我应该使用什么代替 app.config 来配置字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13703292/

相关文章:

java - Mono 中的 SystemException 和 ApplicationException 与 Java 中的未检查和已检查异常相同吗?

ios - MVVM跨iOS : how to bind a command with Custom transition when switching to different View model

xamarin - 如何在xamarin中隐藏导航工具栏图标?

android - Mono for Android 可以与 Visual Web Developer Express 一起使用吗?

.net - 如何为 xbuild 添加缺少的程序集引用? (单声道/Linux)

c# - 如何打破 View Controller 和数据源之间的引用循环

iphone - MonoTouch OpenTK 和 UniformMatrix4

c# - 将 Mat 转换为适用于 Android 的 MemoryStream OpenCV

javascript - Monodroid JavaScript 接口(interface)

c# - 使用 visual studio 和 MONO 为 Linux 环境编程