Skip to content

Instantly share code, notes, and snippets.

@luiseduardohd
Last active April 9, 2021 18:26
Show Gist options
  • Save luiseduardohd/b14723631bf3659c1a2bb4c8b1b9d9f9 to your computer and use it in GitHub Desktop.
Save luiseduardohd/b14723631bf3659c1a2bb4c8b1b9d9f9 to your computer and use it in GitHub Desktop.
TypedValueConverter to have typed objects in the conversion
public abstract class TypedValueConverter<TObject, TTarget> : IValueConverter
{
public Type targetType { get; set; }
public object parameterConvert { get; set; }
public object parameterConvertBack { get; set; }
public CultureInfo cultureInfo { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
this.targetType = targetType;
this.parameterConvert = parameter;
this.cultureInfo = cultureInfo;
return Convert((TObject)value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
this.targetType = targetType;
this.parameterConvertBack = parameter;
this.cultureInfo = cultureInfo;
return ConvertBack((TTarget)value);
}
public abstract TTarget Convert(TObject value);
public abstract TObject ConvertBack(TTarget target);
}
public abstract class TypedValueConverter<TObject,TTarget,TConverParameter, TConverBackParameter> : IValueConverter
{
public Type targetType { get; set; }
public TConverParameter parameterConvert { get; set; }
public TConverBackParameter parameterConvertBack { get; set; }
public CultureInfo cultureInfo { get; set; }
public object Convert(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
this.targetType = targetType;
this.parameterConvert = (TConverParameter)parameter;
this.cultureInfo = cultureInfo;
return Convert((TObject)value);
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo cultureInfo)
{
this.targetType = targetType;
this.parameterConvertBack = (TConverBackParameter)parameter;
this.cultureInfo = cultureInfo;
return ConvertBack((TTarget)value);
}
public abstract TTarget Convert(TObject value);
public abstract TObject ConvertBack(TTarget target);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment