SemanticApiVersion Class
Definition
- Namespace
- Codebelt.Extensions.Asp.Versioning
- Assemblies
- Codebelt.Extensions.Asp.Versioning.dll
Represents an Asp.Versioning.ApiVersion that follows Semantic Versioning precedence rules.
public sealed class SemanticApiVersion : ApiVersion, IEquatable<ApiVersion>, IComparable<ApiVersion>, ISpanFormattable, IFormattable
- Inheritance
-
ApiVersionSemanticApiVersion
- Implements
-
IEquatable<ApiVersion>IComparable<ApiVersion>
- Inherited Members
-
ApiVersion.DefaultApiVersion.NeutralApiVersion.GroupVersionApiVersion.MajorVersionApiVersion.MinorVersionApiVersion.Status
Examples
Use SemanticApiVersion when API-version ordering must follow Semantic Versioning while equality still distinguishes exact build identities. In this example, two builds have equal precedence, but they remain different exact API-version values.
using Codebelt.Extensions.Asp.Versioning;
namespace Codebelt.Extensions.Asp.Versioning;
public class SemanticVersionPrecedence
{
public bool HasSamePrecedenceButDifferentIdentity()
{
var buildOne = new SemanticApiVersion(1, 2, 3, buildMetadata: "build.1");
var buildTwo = new SemanticApiVersion(1, 2, 3, buildMetadata: "build.2");
return buildOne.CompareTo(buildTwo) == 0 && !buildOne.Equals(buildTwo);
}
}
Remarks
Equality and hash-code calculation use the complete version identity, including build metadata. Precedence comparisons performed by CompareTo(ApiVersion) ignore build metadata as required by Semantic Versioning.
Constructors
| Name | Description |
|---|---|
| SemanticApiVersion(int, int, int, string, string) | Initializes a new instance of the SemanticApiVersion class. |
Properties
| Name | Description |
|---|---|
| BuildMetadata | Gets the optional build metadata. |
| PatchVersion | Gets the patch version number. |
| Prerelease | Gets the optional pre-release identifier. |
Methods
| Name | Description |
|---|---|
| CompareTo(ApiVersion) | Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. |
| Equals(ApiVersion) | Indicates whether the current object is equal to another object of the same type. |
| Equals(object) | Determines whether the specified object is equal to the current object. |
| FromVersion(Version, Action<VersionConversionOptions>) | Creates a new instance of the SemanticApiVersion class from a Version object. |
| GetHashCode() | Serves as the default hash function. |
| ToString() | Returns a string that represents the current object. |
| ToString(string) | Returns the text representation of the version using the specified format and format provider. Asp.Versioning.ApiVersionFormatProvider |
| ToString(string, IFormatProvider) | Formats the value of the current instance using the specified format. |
| TryFormat(Span<char>, out int, ReadOnlySpan<char>, IFormatProvider) | Tries to format the value of the current instance into the provided span of characters. |