24 lines
990 B
C#
24 lines
990 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Globalization;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Windows.Data;
|
|
using JD.Guinness.WPF.Module.Model;
|
|
|
|
namespace JD.Guinness.WPF.Module.Converter
|
|
{
|
|
public sealed class ChallengeHasPlatformConverter : IValueConverter
|
|
{
|
|
private static bool Has<T>(IEnumerable<APlatformChallenge> challenges) => challenges.OfType<T>().Any();
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
return value is IEnumerable<APlatformChallenge> && parameter is Type type
|
|
? (bool)typeof(ChallengeHasPlatformConverter).GetMethod(nameof(Has), BindingFlags.Static | BindingFlags.NonPublic).MakeGenericMethod(type).Invoke(null, new[] { value })
|
|
: value;
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotSupportedException();
|
|
}
|
|
}
|