Remove verbs from extension methods

Removed the verbs from all extension methods that manipulate
properties which makes the API more succinct and easier to read.

Also added implicit conversion from string to Style.

As a good OSS citizen, I've obsoleted the old methods with
a warning for now, so this shouldn't break anyone using
the old methods.
This commit is contained in:
Patrik Svensson
2020-10-22 00:32:07 +02:00
committed by Patrik Svensson
parent 037a215a78
commit 041bd016a2
53 changed files with 1021 additions and 245 deletions

View File

@ -7,6 +7,25 @@ namespace Spectre.Console
/// </summary>
public static class HasBoxBorderExtensions
{
/// <summary>
/// Sets the border.
/// </summary>
/// <typeparam name="T">An object type with a border.</typeparam>
/// <param name="obj">The object to set the border for.</param>
/// <param name="border">The border to use.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T Border<T>(this T obj, BoxBorder border)
where T : class, IHasBoxBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.Border = border;
return obj;
}
/// <summary>
/// Do not display a border.
/// </summary>
@ -16,7 +35,7 @@ namespace Spectre.Console
public static T NoBorder<T>(this T obj)
where T : class, IHasBoxBorder
{
return SetBorder(obj, BoxBorder.None);
return Border(obj, BoxBorder.None);
}
/// <summary>
@ -28,7 +47,7 @@ namespace Spectre.Console
public static T SquareBorder<T>(this T obj)
where T : class, IHasBoxBorder
{
return SetBorder(obj, BoxBorder.Square);
return Border(obj, BoxBorder.Square);
}
/// <summary>
@ -40,7 +59,7 @@ namespace Spectre.Console
public static T AsciiBorder<T>(this T obj)
where T : class, IHasBoxBorder
{
return SetBorder(obj, BoxBorder.Ascii);
return Border(obj, BoxBorder.Ascii);
}
/// <summary>
@ -52,7 +71,7 @@ namespace Spectre.Console
public static T RoundedBorder<T>(this T obj)
where T : class, IHasBoxBorder
{
return SetBorder(obj, BoxBorder.Rounded);
return Border(obj, BoxBorder.Rounded);
}
/// <summary>
@ -64,7 +83,7 @@ namespace Spectre.Console
public static T HeavyBorder<T>(this T obj)
where T : class, IHasBoxBorder
{
return SetBorder(obj, BoxBorder.Heavy);
return Border(obj, BoxBorder.Heavy);
}
/// <summary>
@ -76,26 +95,7 @@ namespace Spectre.Console
public static T DoubleBorder<T>(this T obj)
where T : class, IHasBoxBorder
{
return SetBorder(obj, BoxBorder.Double);
}
/// <summary>
/// Sets the border.
/// </summary>
/// <typeparam name="T">An object type with a border.</typeparam>
/// <param name="obj">The object to set the border for.</param>
/// <param name="border">The border to use.</param>
/// <returns>The same instance so that multiple calls can be chained.</returns>
public static T SetBorder<T>(this T obj, BoxBorder border)
where T : class, IHasBoxBorder
{
if (obj is null)
{
throw new ArgumentNullException(nameof(obj));
}
obj.Border = border;
return obj;
return Border(obj, BoxBorder.Double);
}
}
}