在 monodroid 或 monotouch 中,我应该使用什么来代替 app.config 来配置字符串? [英] In monodroid or monotouch what should I use instead of app.config for configuration strings?

查看:32
本文介绍了在 monodroid 或 monotouch 中,我应该使用什么来代替 app.config 来配置字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to store development vs production connection strings and configuration strings in a monodroid project. I would normally store it as app settings in a web.config or an app.config, but how should I do it in monodroid and monotouch projects? I would also like for it to switch configurations automatically between debug and release builds just as visual studio does with *.config files. In an iOS app I could store these in a plist but I'd like a cross platform solution in mono.

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

How would I do this in monodroid or monotouch?

推荐答案

你应该只使用带有 #if 声明的静态类.

You should just use a static class with #if declarations.

类似:

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

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

The benefit to using app.config is the ability to change these settings on the file system without recompiling. On mobile, there isn't a good way (especially on iOS) to edit the file after it's deployed. So it's generally better to just use a static class and redeploy when you need to change the values. This will also work on all platforms, because it is just C# code doing the work.

这篇关于在 monodroid 或 monotouch 中,我应该使用什么来代替 app.config 来配置字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆