source code checkin

This commit is contained in:
Brett Hewitson 2021-01-07 16:23:23 +10:00
parent 5f8fb2c825
commit 7e57b72e35
675 changed files with 168433 additions and 0 deletions

View file

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace ServerManagerTool.Common.Serialization
{
public class IniSection
{
public IniSection()
{
SectionName = string.Empty;
Keys = new List<IniKey>();
}
public string SectionName;
public List<IniKey> Keys;
public IniKey AddKey(string keyName, string keyValue)
{
var key = new IniKey() { KeyName = keyName, KeyValue = keyValue };
Keys.Add(key);
return key;
}
public IniKey AddKey(string keyValuePair)
{
var parts = keyValuePair?.Split(new[] { '=' }, 2) ?? new string[1];
if (string.IsNullOrWhiteSpace(parts[0]))
return null;
var key = new IniKey() { KeyName = parts[0] };
if (parts.Length > 1)
key.KeyValue = parts[1];
Keys.Add(key);
return key;
}
public IniKey GetKey(string keyName)
{
return Keys?.FirstOrDefault(s => s.KeyName.Equals(keyName, StringComparison.OrdinalIgnoreCase));
}
public string[] KeysToStringArray()
{
return Keys.Select(k => k.ToString()).ToArray();
}
public void RemoveKey(string keyName)
{
var key = GetKey(keyName);
RemoveKey(key);
}
public void RemoveKey(IniKey key)
{
if (Keys.Contains(key))
Keys.Remove(key);
}
public override string ToString()
{
return $"[{SectionName}]";
}
}
}