INI 格式實體類的實現和使用
一個簡單的實體類例子:
using System;
using System.Collections.Generic;
using System.Text;
using ConfigurationPattern;
using ConfigurationPattern.Patterns;
namespace CfgSample
{
[ConfigurationPattern(TPattern.INI, "DefaultSection")]
class MyIniCfg : Configuration
{
const String MY_INI_CFG_PATH = @"\myXMLcfg.ini";
public MyIniCfg()
: base(MY_INI_CFG_PATH)
{
Random rand = new Random();
m_RandId = rand.Next();
}
private String m_Name;
private byte m_Age;
private int m_RandId;
private String m_ClassName;
private uint m_Year;
Public Propertys#region Public Propertys
[Section("PrivateInfo")]
public String Name
{
get
{
return m_Name;
}
set
{
m_Name = value;
}
}
[Section("PrivateInfo")]
[Key("Age", 18)]
public byte Age
{
get
{
return m_Age;
}
set
{
m_Age = value;
}
}
[Section("ClassInfo")]
[Key("Class")]
public String ClassName
{
get
{
return m_ClassName;
}
set
{
m_ClassName = value;
}
}
[Section("ClassInfo")]
[Key("Year", 1945)]
public uint Year
{
get
{
return m_Year;
}
set
{
m_Year = value;
}
}
[ConfigurationIgnore]
public int RandId
{
get
{
return m_RandId;
}
set
{
m_RandId = value;
}
}
#endregion
}
}