PowerToys/Wox/Converters/ConvertorBase.cs
2014-05-24 14:06:09 +06:00

30 lines
894 B
C#

using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;
namespace Wox.Converters
{
public abstract class ConvertorBase<T> : MarkupExtension, IValueConverter where T : class, new()
{
private static T converter;
/// <summary>
/// Must be implemented in inheritor.
/// </summary>
public abstract object Convert(object value, Type targetType, object parameter, CultureInfo culture);
/// <summary>
/// Override if needed.
/// </summary>
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());
}
}
}