public static bool TryParse(TextSpan field, [NotNullWhen(true)] out AutomaticLanguage?result) { if (!field.StartsWith("AUTO:LANG|")) { result = null; return(false); } var value = field.Substring("AUTO:LANG|".Length); var parts = value.Split('|').ToArray(); Helpers.CheckForMODorCOPYorCLEAR(parts[0]); var firstPart = parts[0]; string?name = null; string?type = null; bool invert = false; bool all = false; if (firstPart.StartsWith("TYPE=")) { type = firstPart.Substring("TYPE=".Length).Value; } else if (firstPart.StartsWith("!TYPE=")) { type = firstPart.Substring("!TYPE=".Length).Value; invert = true; } else if (firstPart.Value == "ALL") { all = true; } else { name = firstPart.Value; } var conditions = new List <Condition>(); foreach (var part in parts.Skip(1)) { if (!Condition.TryParse(part, out Condition? condition)) { throw new ParseFailedException(part, "Unable to parse Condition."); } conditions.Add(condition); } result = new AutomaticLanguage(conditions, name, type, invert, all); return(true); }