/// Compares <see langword="this"/> to the <see cref="AlmostVersion"/> in <paramref name="other"/> using <see cref="Version.CompareTo(Version)"/>
/// or <see cref="string.CompareTo(string)"/>, depending on the current store.
/// </summary>
/// <remarks>
/// The storage methods of the two objects must be the same, or this will throw an <see cref="InvalidOperationException"/>.
/// </remarks>
/// <param name="other">the <see cref="AlmostVersion"/> to compare to</param>
/// <returns>less than 0 if <paramref name="other"/> is considered bigger than <see langword="this"/>, 0 if equal, and greater than zero if smaller</returns>
/// <seealso cref="CompareTo(Version)"/>
publicintCompareTo(AlmostVersionother)
publicintCompareTo(AlmostVersionother)
{
{
if(other==null)return-1;
if(other==null)return-1;
if(storedAs!=other.storedAs)
if(StorageMode!=other.StorageMode)
thrownewInvalidOperationException("Cannot compare AlmostVersions with different stores!");
thrownewInvalidOperationException("Cannot compare AlmostVersions with different stores!");
if(storedAs==StoredAs.SemVer)
returnsemverForm.CompareTo(other.semverForm);
if(StorageMode==StoredAs.SemVer)
returnSemverValue.CompareTo(other.SemverValue);
else
else
returnstrForm.CompareTo(other.strForm);
returnStringValue.CompareTo(other.StringValue);
}
}
/// <summary>
/// Compares <see langword="this"/> to the <see cref="Version"/> in <paramref name="other"/> using <see cref="Version.CompareTo(Version)"/>.
/// </summary>
/// <remarks>
/// The storage method of <see langword="this"/> must be <see cref="StoredAs.SemVer"/>, else an <see cref="InvalidOperationException"/> will
/// be thrown.
/// </remarks>
/// <param name="other">the <see cref="Version"/> to compare to</param>
/// <returns>less than 0 if <paramref name="other"/> is considered bigger than <see langword="this"/>, 0 if equal, and greater than zero if smaller</returns>
/// <seealso cref="CompareTo(AlmostVersion)"/>
publicintCompareTo(Versionother)
publicintCompareTo(Versionother)
{
{
if(storedAs!=StoredAs.SemVer)
if(StorageMode!=StoredAs.SemVer)
thrownewInvalidOperationException("Cannot compare a SemVer version with an AlmostVersion stored as a string!");
thrownewInvalidOperationException("Cannot compare a SemVer version with an AlmostVersion stored as a string!");
returnsemverForm.CompareTo(other);
returnSemverValue.CompareTo(other);
}
}
/// <summary>
/// Performs a strict equality check between <see langword="this"/> and <paramref name="obj"/>.
/// </summary>
/// <remarks>
/// This may return <see langword="false"/> where <see cref="operator ==(AlmostVersion, AlmostVersion)"/> returns <see langword="true"/>
/// </remarks>
/// <param name="obj">the object to compare to</param>
/// <returns><see langword="true"/> if they are equal, <see langword="false"/> otherwise</returns>
/// <seealso cref="object.Equals(object)"/>
publicoverrideboolEquals(objectobj)
publicoverrideboolEquals(objectobj)
{
{
returnobjisAlmostVersionversion&&
returnobjisAlmostVersionversion&&
semverForm==version.semverForm&&
strForm==version.strForm&&
storedAs==version.storedAs;
SemverValue==version.SemverValue&&
StringValue==version.StringValue&&
StorageMode==version.StorageMode;
}
}
/// <summary>
/// Default generated hash code function generated by VS.
/// </summary>
/// <returns>a value unique to each object, except those that are considered equal by <see cref="Equals(object)"/></returns>
/// Compares two versions, only taking into account the numeric part of the version if they are stored as <see cref="Version"/><see langword="sealed"/>,
/// or strict equality if they are stored as <see cref="string"/>s.
/// </summary>
/// <remarks>
/// This is a looser equality than <see cref="Equals(object)"/>, meaning that this may return <see langword="true"/> where <see cref="Equals(object)"/>
/// does not.
/// </remarks>
/// <param name="l">the first value to compare</param>
/// <param name="r">the second value to compare</param>
/// <returns><see langword="true"/> if they are mostly equal, <see langword="false"/> otherwise</returns>