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

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

本文简介:

  public bool ReadBoolean(string Sections, string Key, bool DefaultValue)
  {
   return bool.Parse(this.ReadString(Sections, Key, DefaultValue.ToString()));
  }

  public byte[] ReadByteArray(string Key, int Length)
  {
   return this.ReadByteArray(this.Sections, Key, Length);
  }

  public byte[] ReadByteArray(string Sections, string Key, int Length)
  {
   byte[] buffer1;
   if (Length > 0)
   {
    try
    {
     byte[] buffer2 = new byte[(Length - 1) + 1];
     if (INIManage.GetPrivateProfileStruct(Sections, Key, buffer2, buffer2.Length, this.Filename) == 0)
     {
      return null;
     }
     return buffer2;
    }
    catch (Exception exception1)
    {
     ProjectData.SetProjectError(exception1);
     buffer1 = null;
     ProjectData.ClearProjectError();
     return buffer1;               
    }
   }
   else
   {
    return null;
   }
       
  }


  public int ReadInteger(string Key)
  {
   return this.ReadInteger(Key, 0);
  }

  public int ReadInteger(string Key, int DefaultValue)
  {
   return this.ReadInteger(this.Sections, Key, DefaultValue);
  }

  public int ReadInteger(string Sections, string Key)
  {
   return this.ReadInteger(Sections, Key, 0);
  }

  public int ReadInteger(string Sections, string Key, int DefaultValue)
  {
   int num1;
   try
   {
    num1 = INIManage.GetPrivateProfileInt(Sections, Key, DefaultValue, this.Filename);
   }
   catch (Exception exception1)
   {
    ProjectData.SetProjectError(exception1);
    num1 = DefaultValue;
    ProjectData.ClearProjectError();
    return num1;           
   }
   return num1;
  }

  public long ReadLong(string Key)
  {
   return this.ReadLong(Key, (long) 0);
  }

  public long ReadLong(string Key, long DefaultValue)
  {
   return this.ReadLong(this.Sections, Key, DefaultValue);
  }

  public long ReadLong(string Sections, string Key)
  {
   return this.ReadLong(Sections, Key, 0);
  }

  public long ReadLong(string Sections, string Key, long DefaultValue)
  {
   return long.Parse(this.ReadString(Sections, Key, DefaultValue.ToString()));
  }

  public string ReadString(string Key)
  {
   return this.ReadString(this.Sections, Key);
  }

  public string ReadString(string Sections, string Key)
  {
   return this.ReadString(Sections, Key, "");
  }

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

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

go top