C# 读写ini配置文件(.net/SQL技术交流群206656202 入群需注明博客园)
2014-05-12 19:52
519 查看
using System; using System.IO; using System.Reflection; using System.Runtime.InteropServices; using System.Text; namespace Souxuexiao.Cache { public static class IniConfig { static string ConfigurationFilePath; static IniConfig() { var Ass = Assembly.GetExecutingAssembly(); ConfigurationFilePath = Ass.CodeBase.Replace(System.IO.Path.GetExtension(Ass.CodeBase), ".ini").Replace(@"file:///", ""); } public static string host { get { return Convert.ToString(GetValue("host", "127.0.0.1:5556")); } set { SetValue("host", value); } } public static string slave { get { return Convert.ToString(GetValue("slave", "127.0.0.1:5556")); } set { SetValue("slave", value); } } public static int WritePoolSize { get { return Convert.ToInt32(GetValue("WritePoolSize", "10")); } set { SetValue("WritePoolSize", value); } } public static int ReadPoolSize { get { return Convert.ToInt32(GetValue("ReadPoolSize", "10")); } set { SetValue("ReadPoolSize", value); } } static void SetValue(string keyName, object value) { NativeMethods.WritePrivateProfileString("redis", keyName, value.ToString(), ConfigurationFilePath); } static object GetValue(string keyName, object defaultValue) { StringBuilder retVal = new StringBuilder(1024); int i= NativeMethods.GetPrivateProfileString("redis", keyName, defaultValue.ToString(), retVal, 1024, ConfigurationFilePath); return retVal.ToString(); } } class NativeMethods { [DllImport("kernel32")] internal static extern long WritePrivateProfileString( string appName, string keyName, string value, string fileName); [DllImport("kernel32")] internal static extern int GetPrivateProfileString( string appName, string keyName, string _default, StringBuilder returnedValue, int size, string fileName); } }
相关文章推荐
- .net 实现Office文件预览(.NET、SQL技术交流群206656202,入群需注明来自博客园)
- jQuery跨域请求,跨域Post提交数据的方法(.net/SQL技术交流群206656202 入群需注明博客园)
- jQuery跨域请求,跨域Post提交数据的方法(.net/SQL技术交流群206656202 入群需注明博客园) - 思...
- 【转载】C#.NET 读写 INI配置文件
- C#读写ini配置文件
- [转]用C#读写ini配置文件
- 用C#读写ini配置文件
- c#读写ini配置文件示例
- Windows系统中C#读写ini配置文件的程序代码示例分享
- c#通用配置文件读写类与格式转换(xml,ini,json)
- 用C#读写ini配置文件完整范例
- 用C#读写ini配置文件
- 用C#读写ini配置文件
- [WPF]C#读写ini配置文件【个人学习用】
- C#读写ini配置文件
- c#读写ini配置文件示例
- C#中读写INI配置文件的方法
- 用C#读写ini配置文件
- C#读写ini配置文件
- C#中读写INI配置文件