25 lines
753 B
C#
25 lines
753 B
C#
using System;
|
|
using System.Globalization;
|
|
using Avalonia.Data.Converters;
|
|
using XSDVisualiser.Models;
|
|
|
|
namespace XSDVisualiser.Desktop.Converters
|
|
{
|
|
public class CardinalityToLabelConverter : IValueConverter
|
|
{
|
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
{
|
|
if (value is Occurs occ)
|
|
{
|
|
var min = occ.Min;
|
|
var max = occ.MaxIsUnbounded ? "*" : occ.Max.ToString(culture);
|
|
return $"[{min}..{max}]";
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
|
=> throw new NotSupportedException();
|
|
}
|
|
}
|