Files
spectre.console/src/Spectre.Console/Extensions/HasJustificationExtensions.cs
Patrik Svensson 9ac41ec876 Revert commits related to modernization of code
* Revert f6e1368: "Fixes problems with extension blocks and params keyword"
* Revert 7965168: "Add modernization commit to .git-blame-ignore-revs"
* Revert 3f57df5: "Modernization of the code base"
2026-01-08 14:40:23 +01:00

80 lines
2.6 KiB
C#

namespace Spectre.Console;
/// <summary>
/// Contains extension methods for <see cref="IHasJustification"/>.
/// </summary>
public static class HasJustificationExtensions
{
/// <summary>
/// Sets the justification for an <see cref="IHasJustification"/> object.
/// </summary>
/// <typeparam name="T">The type that can be justified.</typeparam>
/// <param name="obj">The alignable object.</param>
/// <param name="alignment">The alignment.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T Justify<T>(this T obj, Justify? alignment)
where T : class, IHasJustification
{
if (obj is null)
{
throw new System.ArgumentNullException(nameof(obj));
}
obj.Justification = alignment;
return obj;
}
/// <summary>
/// Sets the <see cref="IHasJustification"/> object to be left justified.
/// </summary>
/// <typeparam name="T">The type that can be justified.</typeparam>
/// <param name="obj">The alignable object.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T LeftJustified<T>(this T obj)
where T : class, IHasJustification
{
if (obj is null)
{
throw new System.ArgumentNullException(nameof(obj));
}
obj.Justification = Console.Justify.Left;
return obj;
}
/// <summary>
/// Sets the <see cref="IHasJustification"/> object to be centered.
/// </summary>
/// <typeparam name="T">The type that can be justified.</typeparam>
/// <param name="obj">The alignable object.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T Centered<T>(this T obj)
where T : class, IHasJustification
{
if (obj is null)
{
throw new System.ArgumentNullException(nameof(obj));
}
obj.Justification = Console.Justify.Center;
return obj;
}
/// <summary>
/// Sets the <see cref="IHasJustification"/> object to be right justified.
/// </summary>
/// <typeparam name="T">The type that can be justified.</typeparam>
/// <param name="obj">The alignable object.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T RightJustified<T>(this T obj)
where T : class, IHasJustification
{
if (obj is null)
{
throw new System.ArgumentNullException(nameof(obj));
}
obj.Justification = Console.Justify.Right;
return obj;
}
}