Files
jdescopingtool/NEW/src/Utils/JdeScoping.SecureStoreManager/Converters/BooleanConverters.cs
T
Joseph Doherty d49330e697 docs: add XML documentation and ConfigManager implementation plans
Add comprehensive XML documentation (param/returns tags) across 132 source
files to improve IntelliSense and API discoverability. Include ConfigManager
design documents and implementation plans for phases 1-9.
2026-01-20 02:26:26 -05:00

153 lines
6.2 KiB
C#

using System.Globalization;
using Avalonia.Data.Converters;
namespace JdeScoping.SecureStoreManager.Converters;
/// <summary>
/// Inverts a boolean value.
/// </summary>
public class InverseBooleanConverter : IValueConverter
{
/// <summary>
/// Converts a boolean value to its inverted counterpart.
/// </summary>
/// <param name="value">The boolean value to invert.</param>
/// <param name="targetType">The target type (ignored).</param>
/// <param name="parameter">An optional parameter (ignored).</param>
/// <param name="culture">The culture information (ignored).</param>
/// <returns>The inverted boolean value, or false if the input is not a boolean.</returns>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return false;
}
/// <summary>
/// Converts a value back to a boolean by inverting it.
/// </summary>
/// <param name="value">The value to invert.</param>
/// <param name="targetType">The target type (ignored).</param>
/// <param name="parameter">An optional parameter (ignored).</param>
/// <param name="culture">The culture information (ignored).</param>
/// <returns>The inverted boolean value, or false if the input is not a boolean.</returns>
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool boolValue)
{
return !boolValue;
}
return false;
}
}
/// <summary>
/// Converts a boolean to a visibility icon (eye open/closed).
/// </summary>
public class BooleanToVisibilityIconConverter : IValueConverter
{
/// <summary>
/// Converts a boolean to a visibility icon string.
/// </summary>
/// <param name="value">The boolean value indicating visibility.</param>
/// <param name="targetType">The target type (ignored).</param>
/// <param name="parameter">An optional parameter (ignored).</param>
/// <param name="culture">The culture information (ignored).</param>
/// <returns>"Hide" if true, "Show" if false or input is not boolean.</returns>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is bool isVisible)
{
// Use simple text icons for cross-platform compatibility
return isVisible ? "Hide" : "Show";
}
return "Show";
}
/// <summary>
/// Converts a value back (not implemented for visibility icons).
/// </summary>
/// <param name="value">The value to convert back (ignored).</param>
/// <param name="targetType">The target type (ignored).</param>
/// <param name="parameter">An optional parameter (ignored).</param>
/// <param name="culture">The culture information (ignored).</param>
/// <returns>Not implemented.</returns>
/// <exception cref="NotImplementedException">Always thrown.</exception>
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
/// <summary>
/// Converts null to bool (null = false, not null = true).
/// </summary>
public class NullToBoolConverter : IValueConverter
{
/// <summary>
/// Converts a value to a boolean based on null status.
/// </summary>
/// <param name="value">The value to check for null.</param>
/// <param name="targetType">The target type (ignored).</param>
/// <param name="parameter">An optional parameter (ignored).</param>
/// <param name="culture">The culture information (ignored).</param>
/// <returns>True if value is not null, false otherwise.</returns>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value != null;
}
/// <summary>
/// Converts a value back (not implemented for null checks).
/// </summary>
/// <param name="value">The value to convert back (ignored).</param>
/// <param name="targetType">The target type (ignored).</param>
/// <param name="parameter">An optional parameter (ignored).</param>
/// <param name="culture">The culture information (ignored).</param>
/// <returns>Not implemented.</returns>
/// <exception cref="NotImplementedException">Always thrown.</exception>
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
/// <summary>
/// Converts a string to bool (empty = false, not empty = true).
/// </summary>
public class StringToBoolConverter : IValueConverter
{
/// <summary>
/// Converts a string to a boolean based on whether it's empty or null.
/// </summary>
/// <param name="value">The string value to check.</param>
/// <param name="targetType">The target type (ignored).</param>
/// <param name="parameter">An optional parameter (ignored).</param>
/// <param name="culture">The culture information (ignored).</param>
/// <returns>True if string is not null or whitespace, false otherwise.</returns>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
if (value is string str)
{
return !string.IsNullOrWhiteSpace(str);
}
return false;
}
/// <summary>
/// Converts a value back (not implemented for string checks).
/// </summary>
/// <param name="value">The value to convert back (ignored).</param>
/// <param name="targetType">The target type (ignored).</param>
/// <param name="parameter">An optional parameter (ignored).</param>
/// <param name="culture">The culture information (ignored).</param>
/// <returns>Not implemented.</returns>
/// <exception cref="NotImplementedException">Always thrown.</exception>
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}