namespace Spectre.Console
{
///
/// Contains extension methods for .
///
public static class AlignableExtensions
{
///
/// Sets the alignment for an object.
///
/// The alignable object type.
/// The alignable object.
/// The alignment.
/// The same instance so that multiple calls can be chained.
public static T SetAlignment(this T obj, Justify alignment)
where T : class, IAlignable
{
if (obj is null)
{
throw new System.ArgumentNullException(nameof(obj));
}
obj.Alignment = alignment;
return obj;
}
///
/// Sets the object to be left aligned.
///
/// The alignable type.
/// The alignable object.
/// The same instance so that multiple calls can be chained.
public static T LeftAligned(this T obj)
where T : class, IAlignable
{
if (obj is null)
{
throw new System.ArgumentNullException(nameof(obj));
}
obj.Alignment = Justify.Left;
return obj;
}
///
/// Sets the object to be centered.
///
/// The alignable type.
/// The alignable object.
/// The same instance so that multiple calls can be chained.
public static T Centered(this T obj)
where T : class, IAlignable
{
if (obj is null)
{
throw new System.ArgumentNullException(nameof(obj));
}
obj.Alignment = Justify.Center;
return obj;
}
///
/// Sets the object to be right aligned.
///
/// The alignable type.
/// The alignable object.
/// The same instance so that multiple calls can be chained.
public static T RightAligned(this T obj)
where T : class, IAlignable
{
if (obj is null)
{
throw new System.ArgumentNullException(nameof(obj));
}
obj.Alignment = Justify.Right;
return obj;
}
}
}