Class SemanticApiVersionFormatter
- Namespace
- Codebelt.Extensions.Asp.Versioning
- Assembly
- Codebelt.Extensions.Asp.Versioning.dll
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
Format(string, object, IFormatProvider)
Converts the value of a specified object to an equivalent string representation using specified format and culture-specific formatting information.
public string Format(string format, object arg, IFormatProvider formatProvider)
Parameters
formatstringA format string containing formatting specifications.
argobjectAn object to format.
formatProviderIFormatProviderAn object that supplies format information about the current instance.
Returns
- string
The string representation of the value of
arg, formatted as specified byformatandformatProvider.
GetFormat(Type)
Returns an object that provides formatting services for the specified type.
public object GetFormat(Type formatType)
Parameters
formatTypeTypeAn object that specifies the type of format object to return.
Returns
- object
An instance of the object specified by
formatType, if the IFormatProvider implementation can supply that type of object; otherwise, null.
GetInstance(IFormatProvider)
Gets a semantic API version formatter from the specified formatProvider.
public static SemanticApiVersionFormatter GetInstance(IFormatProvider formatProvider)
Parameters
formatProviderIFormatProviderThe format provider to inspect.
Returns
- SemanticApiVersionFormatter
A semantic API version formatter.