public Dependency(DependencyType DependencyType, String DependentModName, DependencyComparisonType DependencyComparisonType, ModVersion DependentModVersion) { ObjectValidator.ValidateRequiredObject(DependencyType, nameof(DependencyType)); StringValidator.ValidateRequiredStringWithMaxLength(DependentModName, nameof(DependentModName), Mod.NameLength); this.DependencyType = DependencyType; this.DependentModName = DependentModName; this.DependencyComparisonType = DependencyComparisonType != null ? new DependencyComparisonType(DependencyComparisonType) : null; this.DependentModVersion = DependentModVersion != null ? new ModVersion(DependentModVersion) : null; }
public static Dependency For(String dependencyString) { StringValidator.ValidateRequiredString(dependencyString, nameof(dependencyString)); Regex dependencyStringCaptureRegex = new Regex(Dependency.DependencyStringCapturePattern); Match match = dependencyStringCaptureRegex.Match(dependencyString); if (!match.Success) { throw new ArgumentException($"Unable to parse \"{dependencyString}\" to a valid Dependency due to formatting.", "dependencyString"); } String dependencyTypeValue = match.Groups[1].Value; String dependentModNameValue = match.Groups[2].Value; String dependencyComparisonTypeValue = match.Groups[3].Value; String modVersionValue = match.Groups[4].Value; if (dependentModNameValue.Length > Mod.NameLength) { throw new ArgumentException($"The mod name specified exceeds the maximum length of {Mod.NameLength}.", "dependencyString"); } Regex modVersionFormatCheckRegex = new Regex(FactorioVersion.FactorioVersionStringCapturePattern); Match modVersionFormatCheckMatch = modVersionFormatCheckRegex.Match(modVersionValue); // TODO: We may want to throw a specific exception if we get a ModVersion in the format of a FactorioVersion when the ModName isn't "base". if (dependentModNameValue == "base" && modVersionFormatCheckMatch.Success) { modVersionValue += @".0"; } return(new Dependency { DependencyType = dependencyTypeValue == null?DependencyType.For("") : DependencyType.For(dependencyTypeValue), DependentModName = dependentModNameValue, DependencyComparisonType = (String.IsNullOrEmpty(dependencyComparisonTypeValue)) ? null : DependencyComparisonType.For(dependencyComparisonTypeValue), DependentModVersion = (String.IsNullOrEmpty(modVersionValue)) ? null : ModVersion.For(modVersionValue) }); }