private static bool TryParseVersion(string version, ref VersionUtils.VersionResult result) { if (version == null) { result.SetFailure(VersionUtils.ParseFailureKind.ArgumentNullException); return(false); } string[] strArray = version.Split(VersionUtils.SeparatorsArray); int length = strArray.Length; if (length < 2 || length > 4) { result.SetFailure(VersionUtils.ParseFailureKind.ArgumentException); return(false); } int parsedComponent1; int parsedComponent2; if (!VersionUtils.TryParseComponent(strArray[0], "version", ref result, out parsedComponent1) || !VersionUtils.TryParseComponent(strArray[1], "version", ref result, out parsedComponent2)) { return(false); } int num = length - 2; if (num > 0) { int parsedComponent3; if (!VersionUtils.TryParseComponent(strArray[2], "build", ref result, out parsedComponent3)) { return(false); } if (num - 1 > 0) { int parsedComponent4; if (!VersionUtils.TryParseComponent(strArray[3], "revision", ref result, out parsedComponent4)) { return(false); } result.m_parsedVersion = new Version(parsedComponent1, parsedComponent2, parsedComponent3, parsedComponent4); } else { result.m_parsedVersion = new Version(parsedComponent1, parsedComponent2, parsedComponent3); } } else { result.m_parsedVersion = new Version(parsedComponent1, parsedComponent2); } return(true); }
private static bool TryParseComponent(string component, string componentName, ref VersionUtils.VersionResult result, out int parsedComponent) { if (!int.TryParse(component, NumberStyles.Integer, (IFormatProvider)CultureInfo.InvariantCulture, out parsedComponent)) { result.SetFailure(VersionUtils.ParseFailureKind.FormatException, component); return(false); } if (parsedComponent >= 0) { return(true); } result.SetFailure(VersionUtils.ParseFailureKind.ArgumentOutOfRangeException, componentName); return(false); }