You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have the following converter with the following types. Roslyn reports the following error:
WPF0072: ValueConversion must use correct types Expected: System.ComponentModel.IDataErrorInfo
[ValueConversion(typeof(BaseClass), typeof(string))]
public sealed class Test : IValueConverter
{
public static readonly Test Default = new Test();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Sub1 a)
{
return string.Empty;
}
if (value is Sub2 rm)
{
return string.Empty;
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
public class BaseClass: IDataErrorInfo
{
public string Error { get; } = "";
public string this[string columnName] => throw new NotImplementedException();
}
public class Sub1 : BaseClass
{
}
public class Sub2 : BaseClass
{
}
This is wrong since not IDataErrorInfo should be allowed but BaseClass
[Test]
public static void Inheritance()
{
var code = @"
namespace Gu.Wpf.ToolTips.Demo.Wpf
{
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;
using System.ComponentModel;
public class BaseClass: IDataErrorInfo
{
public string Error { get; } = "";
public string this[string columnName] => throw new NotImplementedException();
}
public class Sub1 : BaseClass
{
}
public class Sub2 : BaseClass
{
}
[ValueConversion(typeof(BaseClass), typeof(string))]
public sealed class Test : IValueConverter
{
public static readonly Test Default = new Test();
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is Sub1 a)
{
return string.Empty;
}
if (value is Sub2 rm)
{
return string.Empty;
}
return string.Empty;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}";
RoslynAssert.Valid(Analyzer, code);
}
The text was updated successfully, but these errors were encountered:
I have the following converter with the following types. Roslyn reports the following error:
This is wrong since not
IDataErrorInfo
should be allowed butBaseClass
Inspecting your code I found out, that
WpfAnalyzers/WpfAnalyzers/Helpers/Walkers/ConversionWalker.cs
Lines 158 to 161 in 69f1c3b
Reproduction steps
Add the following test method to Valid.cs of WPF0072 tests, debug tests and set breakpoint to
WpfAnalyzers/WpfAnalyzers/Helpers/Walkers/ConversionWalker.cs
Line 160 in 69f1c3b
set
variable.The text was updated successfully, but these errors were encountered: