2using System.Collections.Generic;
21 public string?
Name {
get;
set; }
27 public List<ConfigCommand>
Commands {
get;
private set; } =
new();
35 public IEnumerable<ConfigCommand>
this[
string key] =>
Commands.Where(c => c.Name == key);
45 public void SetLine(
string line,
int order)
47 if (
string.IsNullOrWhiteSpace(line) || line[0] ==
'[')
64 public void Remove(IEnumerable<string> keys)
72 public void Remove(params
string[] keys) =>
Remove(keys.AsEnumerable());
83 this[key].Append(fallback).FirstOrDefault();
93 char typeChar = (char)type;
94 string typeString = typeChar == 0 ?
"" : typeChar.ToString();
95 var order = Commands.Count > 0 ?
Commands.Max(s => s.Order) + 1 : 0;
96 SetLine(typeString + key +
"=" + value, order);
104 foreach(var command
in from.Commands)
106 switch (command.Type)
109 var index =
Commands.FindIndex(c => c.Name == command.Name);
112 var existingCommand =
Commands[index];
113 existingCommand.Value = command.Value;
122 if (
Commands.Any(c => c == command))
continue;
129 var inverseCommand = command;
130 inverseCommand.Type = inverseCommandType;
131 if (
Commands.Any(c => c == inverseCommand))
152 var body =
string.Join(Environment.NewLine,
Commands.Select(c => c.Serialize()));
153 return Environment.NewLine +
"[" +
Name +
"]" + Environment.NewLine + body;
Represents a section block in an Unreal INI configuration under a [SectionName] header.
void Set(string key, string value, CommandType type=CommandType.Set)
Set or add an individual config item.
void Remove(params string[] keys)
Remove all given keys from this section.
void Remove(IEnumerable< string > keys)
Remove all given keys from this section.
void SetLine(string line, int order)
Parse an entire config item (or a line) as a command and add it to this section.
string? Name
Section name without square brackets.
int Order
Maintain the original position for this section as they were in the source file so serialization does...
List< ConfigCommand > Commands
Individual config items underneath this section. Here it's referred to as commands because Unreal INI...
string Serialize()
Convert this section to INI format.
ConfigCommand GetFirst(string key, ConfigCommand fallback=default)
Gets a config item in this section with specified key.
ConfigSection Copy()
Deep copy this section.
void Merge(ConfigSection from)
Merge another section into this one, overriding existing values and adding new ones.
CommandType
Unreal INI config items are read top to bottom, reading like individual commands, especially when man...
Structural representation of a config line in Unreal.