using System; using System.Collections.Generic; using System.Globalization; using Avalonia.Data.Converters; namespace DispenserUI.ViewModels.Converter; public class UserRoleConverter : IValueConverter { private static readonly List Roles = ["普通用户", "管理员"]; public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { return Roles[(int)value!]; } public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { for (var i = 0; i < Roles.Count; i++) if (ReferenceEquals(Roles[i], value)) return i; return 0; } }