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

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

问题描述

我想将开发vs生产连接字符串和配置字符串存储在一个monodroid项目中.我通常将其作为应用程序设置存储在web.config或app.config中,但是我应该如何在monodroid和monotouch项目中进行呢?我还希望它可以像Visual Studio使用* .config文件一样在调试版本和发行版本之间自动切换配置.在iOS应用中,我可以将这些存储在plist中,但我希望使用Mono的跨平台解决方案.

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天全站免登陆