State/IToggleStateExtensions.cs

15 lines
757 B
C#
Raw Normal View History

namespace Syntriax.Modules.ToggleState
{
public static class IToggleStateExtensions
{
/// <summary>
/// Checks if the provided parameter IToggleState is toggled, if the parameter is null returns the nullValue parameter
/// </summary>
/// <param name="toggleState">IToggleState to be checked if toggled or not</param>
/// <param name="nullValue">The value that will be returned if toggleState is null. Default value: true</param>
/// <returns>IToggleState's toggle value, or if null return nullValue parameter</returns>
public static bool IsToggledNullChecked(this IToggleState toggleState, bool nullValue = true)
=> toggleState == null ? nullValue : toggleState.IsToggled;
}
}