public
class
InIHelper
{
private
static
string FileName = Application.StartupPath +
"\\AppConfig.ini"
;
public
static
T ReadConfig<T>(string section, string key)
{
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);
}
}
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);
}
}