支持加载 XSD

This commit is contained in:
2022-01-25 19:05:37 +01:00
parent 289f6551c1
commit ce26ef298e
11 changed files with 435 additions and 86 deletions

View File

@@ -0,0 +1,20 @@
using System;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
namespace HashCalculator.GUI.Converters
{
class MultiBooleanConjunctionConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
return values.Cast<bool>().Aggregate((a, b) => a && b);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,45 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
namespace HashCalculator.GUI.Converters
{
class MultiValueAggregateConverter : List<IValueConverter?>, IMultiValueConverter
{
public IMultiValueConverter? Converter { get; set; }
public IValueConverter? PostProcess { get; set; }
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (Converter is not { } converter)
{
throw new InvalidOperationException($"{nameof(Converter)} of {nameof(MultiValueAggregateConverter)} is null");
}
if (Count > 0)
{
values = values.ToArray(); // 复制一份
var length = Math.Min(Count, values.Length);
for (var i = 0; i < length; ++i)
{
if (this[i] is IValueConverter c)
{
values[i] = c.Convert(values[i], targetType, parameter, culture);
}
}
}
var result = converter.Convert(values, targetType, parameter, culture);
if (PostProcess is not { } postConverter)
{
return result;
}
return postConverter.Convert(result, targetType, parameter, culture);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}