Table of Contents

Class VersionConversionOptions

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

Provides programmatic configuration for version conversion operations.

public class VersionConversionOptions : IValidatableParameterObject, IParameterObject
Inheritance
VersionConversionOptions
Implements

Examples

Use VersionConversionOptions to control how a .NET Version is translated into a SemanticApiVersion by SemanticApiVersion.FromVersion. The options let callers decide whether the Revision component is folded into the build metadata and which identifier labels that segment. Configure a VersionConversionOptions instance, validate it with ValidateOptions, then pass it through the Action<VersionConversionOptions> overload of SemanticApiVersion.FromVersion. The example below opts into revision mapping and renames the build-metadata key to build, so a four-part Version(1, 2, 3, 4) renders as 1.2.3+build.4.

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

namespace Codebelt.Extensions.Asp.Versioning;

public class SemanticVersionFromVersionSetup
{
    public string ConvertAssemblyVersionToSemantic()
    {
        var options = new VersionConversionOptions
        {
            IncludeRevision = true,
            RevisionIdentifier = "build"
        };

        var assemblyVersion = new Version(1, 2, 3, 4);
        return SemanticApiVersion.FromVersion(assemblyVersion, o =>
        {
            o.IncludeRevision = options.IncludeRevision;
            o.RevisionIdentifier = options.RevisionIdentifier;
        }).ToString();
    }
}

Remarks

This class is used to configure how .NET Version objects are converted to semantic API versions.

Constructors

VersionConversionOptions()

Initializes a new instance of the VersionConversionOptions class.

public VersionConversionOptions()

Remarks

The following table shows the initial property values for an instance of VersionConversionOptions.

PropertyInitial Value
IncludeRevisionfalse
RevisionIdentifierrevision

Properties

IncludeRevision

Gets or sets a value indicating whether the Revision component should be included in the converted semantic version.

public bool IncludeRevision { get; set; }

Property Value

bool

true if the revision component should be included; otherwise, false.

RevisionIdentifier

Gets or sets the identifier to use for the revision component when included in the semantic version build metadata.

public string RevisionIdentifier { get; set; }

Property Value

string

The identifier used for the revision build metadata. The default value is revision.

Methods

ValidateOptions()

Validates the current state of the options.

public void ValidateOptions()

Exceptions

InvalidOperationException

Thrown when IncludeRevision is true and RevisionIdentifier is null, empty, or whitespace.

InvalidOperationException

Thrown when RevisionIdentifier is not a valid semantic version build metadata identifier.

See Also