Table of Contents

Class MapToSemanticApiVersionAttribute

Namespace
Codebelt.Extensions.Asp.Versioning
Assembly
Codebelt.Extensions.Asp.Versioning.dll

Maps an API implementation to a semantic API version.

public sealed class MapToSemanticApiVersionAttribute : MapToApiVersionAttribute, IApiVersionProvider
Inheritance
ApiVersionsBaseAttribute
MapToApiVersionAttribute
MapToSemanticApiVersionAttribute
Implements
IApiVersionProvider
Inherited Members
ApiVersionsBaseAttribute.Equals(object)
ApiVersionsBaseAttribute.GetHashCode()
ApiVersionsBaseAttribute.Versions

Examples

Use MapToSemanticApiVersionAttribute when one implementation advertises multiple semantic API versions and a specific action should handle only one of them. The example constructs the same metadata an action attribute declaration would create and reads back the mapped semantic API version.

using System.Linq;
using Codebelt.Extensions.Asp.Versioning;

namespace Codebelt.Extensions.Asp.Versioning;

public class SemanticActionMapping
{
    public string GetMappedVersion()
    {
        var attribute = new MapToSemanticApiVersionAttribute("1.2.3-alpha+build.5");
        var version = attribute.Versions.OfType<SemanticApiVersion>().Single();

        return version.ToString();
    }
}

Constructors

MapToSemanticApiVersionAttribute(int, int, int, string, string)

Initializes a new instance of the MapToSemanticApiVersionAttribute class.

public MapToSemanticApiVersionAttribute(int major, int minor, int patch, string prerelease = null, string buildMetadata = null)

Parameters

major int

The major version number.

minor int

The minor version number.

patch int

The patch version number.

prerelease string

The optional pre-release identifier.

buildMetadata string

The optional build metadata.

Exceptions

ArgumentOutOfRangeException

major, minor, or patch is less than zero.

ArgumentException

prerelease is not a valid semantic version pre-release identifier - or - buildMetadata is not valid semantic version build metadata.

MapToSemanticApiVersionAttribute(string)

Initializes a new instance of the MapToSemanticApiVersionAttribute class.

public MapToSemanticApiVersionAttribute(string version)

Parameters

version string

The semantic API version string to parse.

Exceptions

FormatException

version is not a valid semantic API version.

See Also

MapToApiVersionAttribute