mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-12-30 09:48:03 +01:00
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.
48 lines
1.5 KiB
C#
48 lines
1.5 KiB
C#
using System;
|
|
|
|
namespace Spectre.Console
|
|
{
|
|
/// <summary>
|
|
/// Contains extension methods for <see cref="IExpandable"/>.
|
|
/// </summary>
|
|
public static class ExpandableExtensions
|
|
{
|
|
/// <summary>
|
|
/// Tells the specified object to not expand to the available area
|
|
/// but take as little space as possible.
|
|
/// </summary>
|
|
/// <typeparam name="T">The expandable object.</typeparam>
|
|
/// <param name="obj">The object to collapse.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static T Collapse<T>(this T obj)
|
|
where T : class, IExpandable
|
|
{
|
|
if (obj is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(obj));
|
|
}
|
|
|
|
obj.Expand = false;
|
|
return obj;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Tells the specified object to expand to the available area.
|
|
/// </summary>
|
|
/// <typeparam name="T">The expandable object.</typeparam>
|
|
/// <param name="obj">The object to expand.</param>
|
|
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
|
public static T Expand<T>(this T obj)
|
|
where T : class, IExpandable
|
|
{
|
|
if (obj is null)
|
|
{
|
|
throw new ArgumentNullException(nameof(obj));
|
|
}
|
|
|
|
obj.Expand = true;
|
|
return obj;
|
|
}
|
|
}
|
|
}
|