mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-06-19 13:28:16 +08:00

committed by
Patrik Svensson

parent
0a0380ae0a
commit
3f2ca49071
83
src/Spectre.Console/Extensions/CalendarExtensions.cs
Normal file
83
src/Spectre.Console/Extensions/CalendarExtensions.cs
Normal file
@ -0,0 +1,83 @@
|
||||
using System;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="Calendar"/>.
|
||||
/// </summary>
|
||||
public static class CalendarExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds a calendar event.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar to add the calendar event to.</param>
|
||||
/// <param name="date">The calendar event date.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar AddCalendarEvent(this Calendar calendar, DateTime date)
|
||||
{
|
||||
return AddCalendarEvent(calendar, string.Empty, date.Year, date.Month, date.Day);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a calendar event.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar to add the calendar event to.</param>
|
||||
/// <param name="description">The calendar event description.</param>
|
||||
/// <param name="date">The calendar event date.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar AddCalendarEvent(this Calendar calendar, string description, DateTime date)
|
||||
{
|
||||
return AddCalendarEvent(calendar, description, date.Year, date.Month, date.Day);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a calendar event.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar to add the calendar event to.</param>
|
||||
/// <param name="year">The year of the calendar event.</param>
|
||||
/// <param name="month">The month of the calendar event.</param>
|
||||
/// <param name="day">The day of the calendar event.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar AddCalendarEvent(this Calendar calendar, int year, int month, int day)
|
||||
{
|
||||
return AddCalendarEvent(calendar, string.Empty, year, month, day);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a calendar event.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar.</param>
|
||||
/// <param name="description">The calendar event description.</param>
|
||||
/// <param name="year">The year of the calendar event.</param>
|
||||
/// <param name="month">The month of the calendar event.</param>
|
||||
/// <param name="day">The day of the calendar event.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar AddCalendarEvent(this Calendar calendar, string description, int year, int month, int day)
|
||||
{
|
||||
if (calendar is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(calendar));
|
||||
}
|
||||
|
||||
calendar.CalendarEvents.Add(new CalendarEvent(description, year, month, day));
|
||||
return calendar;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the calendar's highlight <see cref="Style"/>.
|
||||
/// </summary>
|
||||
/// <param name="calendar">The calendar.</param>
|
||||
/// <param name="style">The highlight style.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static Calendar SetHighlightStyle(this Calendar calendar, Style? style)
|
||||
{
|
||||
if (calendar is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(calendar));
|
||||
}
|
||||
|
||||
calendar.HightlightStyle = style ?? Style.Plain;
|
||||
return calendar;
|
||||
}
|
||||
}
|
||||
}
|
73
src/Spectre.Console/Extensions/HasCultureExtensions.cs
Normal file
73
src/Spectre.Console/Extensions/HasCultureExtensions.cs
Normal file
@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Spectre.Console
|
||||
{
|
||||
/// <summary>
|
||||
/// Contains extension methods for <see cref="IHasCulture"/>.
|
||||
/// </summary>
|
||||
public static class HasCultureExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Sets the culture.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||
/// <param name="obj">The object to set the culture for.</param>
|
||||
/// <param name="culture">The culture to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T SetCulture<T>(this T obj, CultureInfo culture)
|
||||
where T : class, IHasCulture
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
if (culture is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(culture));
|
||||
}
|
||||
|
||||
obj.Culture = culture;
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the culture.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||
/// <param name="obj">The object to set the culture for.</param>
|
||||
/// <param name="name">The culture to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T SetCulture<T>(this T obj, string name)
|
||||
where T : class, IHasCulture
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Culture = CultureInfo.GetCultureInfo(name);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the culture.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">An object type with a culture.</typeparam>
|
||||
/// <param name="obj">The object to set the culture for.</param>
|
||||
/// <param name="name">The culture to set.</param>
|
||||
/// <returns>The same instance so that multiple calls can be chained.</returns>
|
||||
public static T SetCulture<T>(this T obj, int name)
|
||||
where T : class, IHasCulture
|
||||
{
|
||||
if (obj is null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(obj));
|
||||
}
|
||||
|
||||
obj.Culture = CultureInfo.GetCultureInfo(name);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user