/// <summary> /// Tries to parse a <see cref="DependencyVersion" /> from the specified version string. /// </summary> /// <param name="version">The version.</param> /// <param name="acceptWildcards">if set to <c>true</c> the parsing will take into account wildcard parts and possibly return a <see cref="WildcardDependencyVersion"/>.</param> /// <param name="outVersion">The parsed version.</param> /// <returns> /// Returns true if the parsing was successfuly. Otherwise, returns false. /// </returns> /// <exception cref="NAMEException">The JSON returned from the service is not a valid manifest.</exception> public static bool TryParse(string version, bool acceptWildcards, out DependencyVersion outVersion) { outVersion = null; if (version == null) { return(false); } var parsedVersion = ParseVersion(version); if (parsedVersion == null) { outVersion = default(DependencyVersion); return(false); } if (!parsedVersion.Item1.HasValue || !parsedVersion.Item2.HasValue || !parsedVersion.Item3.HasValue) { if (acceptWildcards == false) { return(false); } if (!parsedVersion.Item1.HasValue) { outVersion = new WildcardDependencyVersion(); } else if (!parsedVersion.Item2.HasValue) { outVersion = new WildcardDependencyVersion(parsedVersion.Item1.Value); } else { outVersion = new WildcardDependencyVersion(parsedVersion.Item1.Value, parsedVersion.Item2.Value); } return(true); } outVersion = new DependencyVersion(parsedVersion.Item1.Value, parsedVersion.Item2.Value, parsedVersion.Item3.Value); return(true); }
public void Version_PatchWildcard_Operators() { var version = new WildcardDependencyVersion(3, 1); Assert.True(version > new DependencyVersion(2)); Assert.True(version > new DependencyVersion(3, 1, 123)); Assert.True(version > new DependencyVersion(3, 1)); Assert.True(version > new DependencyVersion(3, 1, uint.MaxValue)); Assert.True(version < new DependencyVersion(4)); Assert.False(version == new DependencyVersion(3)); Assert.True(version != new DependencyVersion(3)); Assert.True(version == new WildcardDependencyVersion(3, 1)); Assert.False(version == new WildcardDependencyVersion(3)); Assert.True(version < new DependencyVersion(4)); Assert.True(version < new WildcardDependencyVersion(4)); Assert.True(version < new WildcardDependencyVersion(3)); Assert.True(version > new DependencyVersion(2)); Assert.False(version <= new DependencyVersion(3)); Assert.True(version >= new DependencyVersion(3)); }
public void Version_MajorWildcard_ToString() { var version = new WildcardDependencyVersion(1, 2); Assert.Equal("1.2.*", version.ToString()); }