-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WPF0071 should figure out types here #192
Comments
[Test]
public void Issue192()
{
var testCode = @"
namespace RoslynSandbox
{
using System;
using System.Globalization;
using System.Windows.Data;
public class StringComparisonToBoolConverter : IValueConverter
{
public static readonly StringComparisonToBoolConverter TrueWhenOrdinal = new StringComparisonToBoolConverter(StringComparison.Ordinal);
public static readonly StringComparisonToBoolConverter TrueWhenOrdinalIgnoreCase = new StringComparisonToBoolConverter(StringComparison.OrdinalIgnoreCase);
private readonly StringComparison trueWhen;
private StringComparisonToBoolConverter(StringComparison trueWhen)
{
this.trueWhen = trueWhen;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Equals(value, this.trueWhen);
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException($""{nameof(StringComparisonToBoolConverter)} can only be used in OneWay bindings"");
}
}
}";
var fixedCode = @"
namespace RoslynSandbox
{
using System;
using System.Globalization;
using System.Windows.Data;
[ValueConversion(typeof(StringComparison), typeof(bool))]
public class StringComparisonToBoolConverter : IValueConverter
{
public static readonly StringComparisonToBoolConverter TrueWhenOrdinal = new StringComparisonToBoolConverter(StringComparison.Ordinal);
public static readonly StringComparisonToBoolConverter TrueWhenOrdinalIgnoreCase = new StringComparisonToBoolConverter(StringComparison.OrdinalIgnoreCase);
private readonly StringComparison trueWhen;
private StringComparisonToBoolConverter(StringComparison trueWhen)
{
this.trueWhen = trueWhen;
}
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
return Equals(value, this.trueWhen);
}
object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotSupportedException($""{nameof(StringComparisonToBoolConverter)} can only be used in OneWay bindings"");
}
}
}";
AnalyzerAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, testCode, fixedCode, allowCompilationErrors: AllowCompilationErrors.Yes);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: