public ModMeta Normalise() { lock (this) { Id = NormString(Id); NormTextSet(ref Name); if (Name == null && Id != null) { Name = new TextSet { Default = Id } } ; NormStringArray(ref Flags); if (Flags != null) { Flags = Flags.Select(e => e.ToLowerInvariant()).ToArray(); } NormStringArray(ref Lang); Duration = NormString(Duration); NormTextSet(ref Description); NormTextSet(ref Author); NormTextSet(ref Url); NormTextSet(ref Contact); NormTextSet(ref Copyright); NormAppVer(ref Avoids); NormAppVer(ref Requires); NormAppVer(ref Disables); NormStringArray(ref Mods); NormDllMeta(ref Dlls); NormDictArray(ref Actions); ConfigType = NormString(ConfigType); return(this); } }
private static TextSet AssignTextSetProp(TextSet e, string prop, object val) { prop = prop.Trim(); var txt = val.ToString().Trim(); if (prop.Length == 0 || txt.Length == 0) { return(e); } if (e.Default == null) { e.Default = txt; e.Dict = new Dictionary <string, string>(); } e.Dict.Add(prop, txt); return(e); }
private static void NormTextSet(ref TextSet val) { if (val == null) { return; } var dict = val.Dict; if (dict != null) { foreach (var pair in dict.ToArray()) { string key = NormString(pair.Key), txt = NormString(pair.Value); if (key == null || txt == null) { dict.Remove(pair.Key); } if (pair.Key == key && pair.Value == txt) { continue; } dict.Remove(pair.Key); dict[key] = txt; } if (dict.Count == 0) { val.Dict = dict = null; } } val.Default = NormString(val.Default); if (val.Default == null) { val.Default = dict?.First().Value; if (val.Default == null) { val = null; } } }