mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2026-02-10 04:13:32 +01:00
* Revertf6e1368: "Fixes problems with extension blocks and params keyword" * Revert7965168: "Add modernization commit to .git-blame-ignore-revs" * Revert3f57df5: "Modernization of the code base"
80 lines
2.6 KiB
C#
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;
|
|
}
|
|
} |