Table of Contents

SemanticApiVersionFormatter Class

Definition

Namespace
Codebelt.Extensions.Asp.Versioning
Assemblies
Codebelt.Extensions.Asp.Versioning.dll
Source
src/Codebelt.Extensions.Asp.Versioning/SemanticApiVersionFormatter.cs

Formats instances of SemanticApiVersion.

public sealed class SemanticApiVersionFormatter : IFormatProvider, ICustomFormatter
Inheritance
SemanticApiVersionFormatter
Implements

Examples

Use SemanticApiVersionFormatter when a semantic API version needs the same formatting tokens used by Asp.Versioning plus patch, pre-release, and build metadata output. The formatter below creates a complete display value and a compact group name from the same version.

using Codebelt.Extensions.Asp.Versioning;

namespace Codebelt.Extensions.Asp.Versioning;

public class SemanticVersionDisplay
{
    public (string DisplayName, string GroupName) Format()
    {
        var version = new SemanticApiVersion(1, 2, 3, "alpha", "build.5");
        var formatter = SemanticApiVersionFormatter.GetInstance(null);

        var displayName = formatter.Format("G", version, null);
        var groupName = formatter.Format("VV'-'S", version, null);

        return (displayName, groupName);
    }
}

Methods

Name Description
Format(string, object, IFormatProvider)

Converts the value of a specified object to an equivalent string representation using specified format and culture-specific formatting information.

GetFormat(Type)

Returns an object that provides formatting services for the specified type.

GetInstance(IFormatProvider)

Gets a semantic API version formatter from the specified formatProvider.

See Also