public Dependency(DependencyType type, string modName, DependencyComparison comparison, AccurateVersion compareVersion) { Type = type; ModName = modName; Comparison = comparison; CompareVersion = compareVersion; }
public static bool TryParse(string value, out Dependency result) { result = null; if (string.IsNullOrWhiteSpace(value)) { return(false); } value = value.Trim(); var type = DependencyType.Normal; if (value[0] == '!') { type = DependencyType.Inverted; value = value.Substring(1).TrimStart(); } else if (value[0] == '?') { type = DependencyType.Optional; value = value.Substring(1).TrimStart(); } else if (value.StartsWith("(?)")) { type = DependencyType.Hidden; value = value.Substring(3).TrimStart(); } if (string.IsNullOrWhiteSpace(value)) { return(false); } const string pattern = @"\A(?<name>[a-zA-Z0-9_\-]+)(?:\s*(?<op><=|>=|<|>|=)\s*(?<ver>\d+(?:\.\d+){0,3}))?\Z"; var match = Regex.Match(value, pattern); if (!match.Success) { return(false); } string name = match.Groups["name"].Value; DependencyComparison comp; AccurateVersion version = default; var opG = match.Groups["op"]; if (opG.Success) { comp = new DependencyComparison(opG.Value); version = AccurateVersion.Parse(match.Groups["ver"].Value); } else { comp = new DependencyComparison(DependencyOperator.None); } result = new Dependency(type, name, comp, version); return(true); }
public Dependency(DependencyType type, string modName, DependencyComparison comparison, AccurateVersion compareVersion) => (Type, ModName, Comparison, CompareVersion) = (type, modName, comparison, compareVersion);