/********************************************************************************
** auth: DBS
** date: 2018/12/11 14:56:55
** desc: 尚未编写描述
** Ver.: V1.0.0
*********************************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace HH.WMS.Common
{
public class InIHelper
{
private static string FileName = Application.StartupPath + "\\AppConfig.ini";
///
/// 读取配置文件
///
///
///
///
///
public static T ReadConfig(string section, string key)
{
try
{
if (File.Exists(FileName))
{
IniFile f = new IniFile(FileName);
string value = f.ReadContentValue(section, key);
if (String.IsNullOrWhiteSpace(value))
return default(T);
if (typeof(T).IsEnum)
return (T)Enum.Parse(typeof(T), value, true);
return (T)Convert.ChangeType(value, typeof(T));
}
else
{
return default(T);
}
}
catch (Exception)
{
return default(T);
}
}
///
/// 写配置文件
///
///
///
///
public static void WriteConfig(string section, string key, string value)
{
//如果文件不存在,则创建
if (!File.Exists(FileName))
{
using (FileStream myFs = new FileStream(FileName, FileMode.Create)) { }
}
IniFile f = new IniFile(FileName);
f.WriteContentValue(section, key, value);
}
}
}