答案:挺久以前写的一个配置文件类,有点儿小问题就是不支持线程安全,一直抽点儿时间改过来,但也一直没做,呵呵,懒啊。
using System;
using System.Collections ;
using System.IO ;
using System.Diagnostics ;
using System.Security.Cryptography ;
namespace Bigeagle.Util
{
/// <summary>
/// 配置文件类,最终类
/// <br>Author: Bigeagle@163.net</br>
/// <br>Date: 2001/09/25</br>
/// <br>History: 2001/10/26 finished</br>
/// <br>ToDo: 现在不是线程安全的方式,如果有时间改动一下</br>
/// </summary>
/// <remarks>很简单的一个类</remarks>
public sealed class Ini
{
/// <summary>
/// 配置文件路径
/// </summary>
private string m_strIniFilePath ;
/// <summary>
/// 是否已经初始化
/// </summary>
private bool m_bIsLoad ;
/// <summary>
/// 属性值数组
/// </summary>
private ArrayList m_arrProperties ;
/// <summary>
/// 配置文件路径
/// </summary>
public string IniFilePath
{
get
{
return m_strIniFilePath ;
}
set
{
m_strIniFilePath = value ;
}
}//end method
/// <summary>
/// 构造函数
/// </summary>
public Ini()
{
m_strIniFilePath = "" ;
m_bIsLoad = false ;
m_arrProperties = new ArrayList() ;
}//end method
/// <summary>
/// 重载构造函数
/// </summary>
/// <param name="a_strIniFilePath">配置文件路径</param>
public Ini(string a_strIniFilePath)
{
m_strIniFilePath = a_strIniFilePath ;
m_bIsLoad = false ;
m_arrProperties = new ArrayList() ;
}//end method
/// <summary>
/// 添加属性
/// </summary>
/// <param name="a_strName">属性名称</param>
/// <param name="a_strValue">属性值</param>
/// <exception cref="Exception"></exception>
/// <remarks>如果已经有指定属性值,抛出异常</remarks>
public void AddProperty(string a_strName , string a_strValue)
{
//检查是否已有该属性
bool bExists = false ;
for(int i = 0 ; i < m_arrProperties.Count ; i ++)
{
Property p = (Property)m_arrProperties[i] ;
if(p.Name == a_strName)
{
bExists = true ;
break ;
}
}
if(!bExists)
{
m_arrProperties.Add(new Property(a_strName , a_strValue)) ;
}
else
{
throw(new Exception("该属性已经存在")) ;
}
}//end method
/// <summary>
/// 设置属性值
/// </summary>
/// <param name="a_strName">属性名称</param>
/// <param name=&quo
上一个:Visual C#如何使用Active X组件
下一个:在.NET(正式版)环境下读写系统日志(From CSDN)