博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C# 读写ini配置文件(.net/SQL技术交流群206656202 入群需注明博客园)
阅读量:7100 次
发布时间:2019-06-28

本文共 1685 字,大约阅读时间需要 5 分钟。

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);}}

转载于:https://www.cnblogs.com/GodIsBoy/p/3724036.html

你可能感兴趣的文章
Servlet的异常处理
查看>>
支付宝 app支付 沙盘使用
查看>>
Redis持久化配置-AOF
查看>>
计算机网络的应用层简单介绍:
查看>>
需求管理之客户需求何时休?
查看>>
Java进化? Kotlin初探与集成Android项目
查看>>
URL中的#
查看>>
CentOS自带mysql配置(密码更改、端口开放访问、添加进系统启动项)
查看>>
MYSQL中动态行数据转列数据
查看>>
anchor_target_layer中的bounding regression
查看>>
[转]怎么解决输入流和输出流编码问题
查看>>
Linux下Jenkins服务器搭建
查看>>
pavenet资源
查看>>
致研究者:2018 AI 研究趋势
查看>>
006-unity3d GUI初识、贴图、自定义鼠标指针
查看>>
Set replication in Hadoop
查看>>
Linux - 进程与内存查看
查看>>
高性能爬虫——asynicio模块
查看>>
Docker容器的数据卷(data volume),数据卷容器,数据卷的备份和还原。
查看>>
win10 字体渲染优化 色彩调整
查看>>