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.
IValueConverter nextConverter = null;
if( convert )
{
if( converterIndex < this.Converters.Count - 1 )
{
nextConverter = this.Converters[converterIndex + 1];
if( nextConverter == null )
throw new InvalidOperationException( "The Converters collection of the ValueConverterGroup contains a null reference at index: " + (converterIndex + 1) );
}
}
else
{
if( converterIndex > 0 )
{
nextConverter = this.Converters[converterIndex - 1];
if( nextConverter == null )
throw new 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;
}