支持加载 XSD
This commit is contained in:
20
Converters/MultiBooleanConjunctionConverter.cs
Normal file
20
Converters/MultiBooleanConjunctionConverter.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
45
Converters/MultiValueAggregateConverter.cs
Normal file
45
Converters/MultiValueAggregateConverter.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user