代码拉取完成,页面将自动刷新
namespace JetbrainsConfig;
using System;
using System.IO;
class Prop
{
string key = "";
string value = "";
bool line = false;
public string Key
{
get => key;
set => key = value ?? throw new ArgumentNullException(nameof(value));
}
public string Value
{
get => value;
set => this.value = value ?? throw new ArgumentNullException(nameof(value));
}
public bool Line
{
get => line;
set => line = value;
}
public override string ToString()
{
if (line)
{
return key;
}
return key + "=" + value;
}
}
public class Properties
{
string path;
List<Prop> props = new List<Prop>();
Dictionary<string, int> dict = new Dictionary<string, int>();
public Properties(string filename)
{
this.path = filename ?? throw new ArgumentNullException(nameof(filename));
string line;
int lineLen = -1;
using (StreamReader sr = new StreamReader(filename))
{
while (sr.Peek() >= 0)
{
var prop = new Prop();
line = sr.ReadLine();
lineLen++;
if (string.IsNullOrEmpty(line) || line.StartsWith('#'))
{
prop.Key = line;
prop.Line = true;
props.Add(prop);
continue;
}
var strings = line.Split('=');
prop.Key = strings[0];
prop.Value = strings[1];
prop.Line = false;
props.Add(prop);
dict.Add(strings[0], lineLen);
}
}
}
public void Add(string key, string value)
{
if (dict.ContainsKey(key))
{
Prop p = props[dict[key]];
p.Value = value;
}
else
{
props.Add(new Prop() { Key = key, Value = value});
}
}
public void Save()
{
if (File.Exists(path))
{
File.Delete(path);
}
FileStream fileStream = File.Create(path);
StreamWriter sw = new StreamWriter(fileStream);
foreach (Prop p in props)
{
sw.WriteLine(p.ToString());
}
sw.Close();
fileStream.Close();
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。