本文主要是介绍C# 代码转PowerShell (读取config文件),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="a1" value="a1_result"/>
</appSettings>
</configuration>
C#代码
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = @"D:\App.config"; ;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
string value = config.AppSettings.Settings["a1"].Value;
Console.WriteLine(value);
C#转PowerShell
$map=New-Object System.Configuration.ExeConfigurationFileMap
$map.ExeConfigFilename="D:\App.config"
### OpenMappedExeConfiguration 是静态函数
### [System.Configuration.ConfigurationUserLevel]::None 枚举
$configobj = [System.Configuration.ConfigurationManager]::OpenMappedExeConfiguration($map,[System.Configuration.ConfigurationUserLevel]::None)
$keys = $configobj.AppSettings.Settings["a1"]
$keys.Value
这篇关于C# 代码转PowerShell (读取config文件)的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!