Dear All,
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace NewTims
{
public class IniFile
{
public string path;
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,
string key, string def, StringBuilder retVal,
int size, string filePath);
public IniFile(string INIPath)
{
path = INIPath;
}
public void IniWriteValue(string Section, string Key, string Value)
{
if (!File.Exists(Directory.GetCurrentDirectory()+this.path));
{
File.Create(this.path);
}
WritePrivateProfileString(Section, Key, Value, this.path);
}
public string IniReadValue(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
GetPrivateProfileString(Section, Key, "", temp, 255, this.path);
return temp.ToString();
}
}
}
I want to write a utility that can be called by the syntax as follows.
IniFile("NewTims");
IniWriteValue("History", "Prior Color");
I encounter an issue as follows. The "path" property should be on the type static.
- However, changing the word from "public" to "static", all the "this.path" are red-lined. Are properties can't be static? Could anybody help me modify the code?
- The line "if (!File.Exists(Directory.GetCurrentDirectoy()+this.path))" is marked "CS0642 Possible mistaken empty statement". Could anybody explain why?