.NET下INI配置文件操作类[4]

[入库:2006年2月23日] [更新:2007年3月24日]

本文简介:

  public bool DeleteKey(string Key)
  {
   bool flag1;
   try
   {
    flag1 = INIManage.WritePrivateProfileString(this.Sections, Key, null, this.Filename) != 0;
   }
   catch (Exception exception1)
   {
    ProjectData.SetProjectError(exception1);
    flag1 = false;
    ProjectData.ClearProjectError();
    return flag1;           
   }
   return flag1;
  }

  public bool DeleteKey(string Section, string Key)
  {
   bool flag1;
   try
   {
    flag1 = INIManage.WritePrivateProfileString(Sections, Key, null, this.Filename) != 0;
   }
   catch (Exception exception1)
   {
    ProjectData.SetProjectError(exception1);
    flag1 = false;
    ProjectData.ClearProjectError();
    return flag1;          
   }
   return flag1;
  }

  public bool DeleteSections(string Section)
  {
   bool flag1;
   try
   {
    flag1 = INIManage.WritePrivateProfileSections(Sections, null, this.Filename) != 0;
   }
   catch (Exception exception1)
   {
    ProjectData.SetProjectError(exception1);
    flag1 = false;
    ProjectData.ClearProjectError();
    return flag1;          
   }
   return flag1;
  }

  #endregion

  public ArrayList GetSectionsNames()
  {
   int num1;
   ArrayList list1 = new ArrayList();
   byte[] buffer1 = new byte[MAX_ENTRY];
   int num2 = 0;
   try
   {
    num1 = INIManage.GetPrivateProfileSectionsNames(buffer1, MAX_ENTRY, this.Filename);
   }
   catch (Exception exception1)
   {
    ProjectData.SetProjectError(exception1);
    ProjectData.ClearProjectError();
    return list1;         
   }
   ASCIIEncoding encoding1 = new ASCIIEncoding();
   if (num1 > 0)
   {
    string text1 = encoding1.GetString(buffer1);
    num1 = 0;
    num2 = -1;
    while (true)
    {
     num1 = text1.IndexOf('\0', (int) (num2 + 1));
     if (((num1 - num2) == 1) || (num1 == -1))
     {
      return list1;
     }
     try
     {
      list1.Add(text1.Substring(num2 + 1, num1 - num2));
     }
     catch (Exception exception2)
     {
      ProjectData.SetProjectError(exception2);
      ProjectData.ClearProjectError();
     }
     num2 = num1;
    }
   }
   return list1;
  }

本文关键:.NET下INI配置文件操作类
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top