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

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

本文简介:

  public string ReadString(string Sections, string Key, string DefaultValue)
  {
   string text1;
   try
   {
    StringBuilder builder1 = new StringBuilder(MAX_ENTRY);
    int num1 = INIManage.GetPrivateProfileString(Sections, Key, DefaultValue, builder1, MAX_ENTRY, this.Filename);
    text1 = builder1.ToString();
   }
   catch (Exception exception1)
   {
    ProjectData.SetProjectError(exception1);
    text1 = DefaultValue;
    ProjectData.ClearProjectError();
    return text1;
         
   }
   return text1;
  }

  #endregion


  #region" INI操作类的Write相关方法 "
 
  public bool Write(string Key, bool Value)
  {
   return this.Write(this.Sections, Key, Value);
  }

  public bool Write(string Key, byte[] Value)
  {
   return this.Write(this.Sections, Key, Value);
  }

  public bool Write(string Key, string Value)
  {
   return this.Write(this.Sections, Key, Value);
  }

  public bool Write(string Key, int Value)
  {
   return this.Write(this.Sections, Key, Value);
  }

  public bool Write(string Key, long Value)
  {
   return this.Write(this.Sections, Key, Value);
  }

  public bool Write(string Sections, string Key, byte[] Value)
  {
   bool flag1;
   try
   {
    flag1 = INIManage.WritePrivateProfileStruct(Sections, Key, Value, Value.Length, this.Filename) != 0;
   }
   catch (Exception exception1)
   {
    ProjectData.SetProjectError(exception1);
    flag1 = false;
    ProjectData.ClearProjectError();
    return flag1;          
   }
   return flag1;
  }

  public bool Write(string Sections, string Key, bool Value)
  {
   return this.Write(Sections, Key, Value.ToString());
  }

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

  public bool Write(string Sections, string Key, long Value)
  {
   return this.Write(Sections, Key, Value.ToString());
  }

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

  #endregion


  #region" INI操作类的Delete相关方法 "

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

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

go top