42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using Avalonia.Data.Converters;
|
|
using Cowain.Base.Helpers;
|
|
using Ke.Bee.Localization.Localizer.Abstractions;
|
|
using System.Collections.ObjectModel;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Reflection.Metadata;
|
|
using System.Text.Json;
|
|
|
|
namespace Cowain.Base.Converters;
|
|
|
|
/// <summary>
|
|
/// 菜单权限转换格式显示
|
|
/// </summary>
|
|
public class MenuActionsConverter : IValueConverter
|
|
{
|
|
private readonly ILocalizer _l;
|
|
public MenuActionsConverter()
|
|
{
|
|
_l = ServiceLocator.GetRequiredService<ILocalizer>();
|
|
}
|
|
|
|
public object? Convert(object? value, Type targetType, object? prefix, CultureInfo culture)
|
|
{
|
|
if (value is ObservableCollection<string> menuActions)
|
|
{
|
|
return JsonSerializer.Serialize(menuActions);
|
|
//return string.Join(',', menuActions);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? prefix, CultureInfo culture)
|
|
{
|
|
if (value is string jsonString)
|
|
{
|
|
return JsonSerializer.Deserialize<ObservableCollection<string>>(jsonString);
|
|
}
|
|
return null;
|
|
}
|
|
}
|