C# 读取属于另一个应用程序的配置文件的最简单方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/239687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Easiest way to read a config file belonging to another application
提问by Matt
Other than using raw XML, is there an easy way in .NET to open and read a config file belonging to another assembly...? I don't need to write to it, just grab a couple of values from it.
除了使用原始 XML 之外,在 .NET 中有没有一种简单的方法来打开和读取属于另一个程序集的配置文件......?我不需要写入它,只需从中获取几个值即可。
采纳答案by DOK
回答by Marc Gravell
Have you tried ConfigurationManager
and OpenExeConfiguration(path)
? (in System.Configuration.dll)
您是否尝试过ConfigurationManager
与OpenExeConfiguration(path)
?(在 System.Configuration.dll 中)
回答by Oliver Slay
Or perhaps you could Serialize a simple class with the [Serializable()] attribute to a file... and deserialize in the other app...
或者,也许您可以将具有 [Serializable()] 属性的简单类序列化到文件中……然后在其他应用程序中反序列化……
http://www.dotnetperls.com/serialize-list
http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx
http://www.dotnetperls.com/serialize-list
http://msdn.microsoft.com/en-us/library/system.serializableattribute.aspx
The sample program shows one short bit of code to serialize to a file and another to read file...
示例程序显示了一小段代码来序列化到一个文件和另一个读取文件...
You can serialize to a file, to XML, to SOAP...
您可以序列化为文件、XML、SOAP...