Skip to content

Instantly share code, notes, and snippets.

@karno
Created November 23, 2010 05:06
Show Gist options
  • Save karno/711286 to your computer and use it in GitHub Desktop.
Save karno/711286 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
namespace Azrael.Converters
{
// Converter templates
public abstract class TwoWayConverter<Source, Target> : IValueConverter
where Source : class
where Target : class
{
public abstract Target ToTarget(Source input, object parameter);
public abstract Source ToSource(Target input, object parameter);
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ToTarget(value as Source, parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ToSource(value as Target, parameter);
}
}
public abstract class OneWayConverter<Source, Target> : IValueConverter
where Source : class
where Target : class
{
public abstract Target ToTarget(Source input, object parameter);
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ToTarget(value as Source, parameter);
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment