protected virtual Type GetTargetType(int converterIndex, Type finalTargetType, bool convert)
{
// If the current converter is not the last/first in the list,
// get a reference to the next/previous converter.
System.Windows.Data.IValueConverter nextConverter = null;
if (convert)
{
if (converterIndex < Converters.Count - 1)
{
nextConverter = Converters[converterIndex + 1];
if (nextConverter == null)
{
throw Log.ErrorAndCreateException<InvalidOperationException>("The Converters collection of the ValueConverterGroup contains a null reference at index: " + (converterIndex + 1));
}
}
}
else
{
if (converterIndex > 0)
{
nextConverter = Converters[converterIndex - 1];
if (nextConverter == null)
{
throw Log.ErrorAndCreateException<InvalidOperationException>("The Converters collection of the ValueConverterGroup contains a null reference at index: " + (converterIndex - 1));
}
}
}
if (nextConverter != null)
{
ValueConversionAttribute conversionAttribute = _cachedAttributes[nextConverter];
// If the Convert method is going to be called, we need to use the SourceType of the next
// converter in the list. If ConvertBack is called, use the TargetType.
return convert ? conversionAttribute.SourceType : conversionAttribute.TargetType;
}
// If the current converter is the last one to be executed return the target type passed into the conversion method.
return finalTargetType;
}