using System; using System.Globalization; using System.Windows.Data; using System.Windows.Markup; namespace Wox.Converters { public abstract class ConvertorBase : MarkupExtension, IValueConverter where T : class, new() { private static T converter; /// /// Must be implemented in inheritor. /// public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture); /// /// Override if needed. /// public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { throw new NotImplementedException(); } public override object ProvideValue(IServiceProvider serviceProvider) { return converter ?? (converter = new T()); } } }