The following class produces a FP - SonarCloud detectes that the line
return value is bool castValue && castValue ? TrueValue : FalseValue;
always evaluates to true - Resharper does not have that problem.
It might be related to the fact that the property names have True and False in their name.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Data;
namespace Sample
{
/// <summary>
/// An <see cref="IValueConverter"/> that compares incoming values with a set of predefined values.
/// The outcome of <see cref="Convert"/>/<see cref="ConvertBack"/> is based on the quality with <see cref="TrueValue"/>/<see cref="FalseValue"/>
/// </summary>
public abstract class GenericEqualityConverter<T> : IValueConverter
{
/// <summary>
/// Initializes a new instance of the <see cref="GenericEqualityConverter{T}"/> class.
/// </summary>
protected GenericEqualityConverter(T trueValue, T falseValue)
{
TrueValue = trueValue;
FalseValue = falseValue;
}
public T TrueValue { get; set; }
public T FalseValue { get; set; }
public virtual object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is bool castValue && castValue ? TrueValue : FalseValue;
}
public virtual object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return value is T castValue && EqualityComparer<T>.Default.Equals(castValue, TrueValue);
}
}
}