Skip to content
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

WPF0072 does not figure out nullable bool here. #232

Open
JohanLarsson opened this issue Sep 6, 2018 · 0 comments
Open

WPF0072 does not figure out nullable bool here. #232

JohanLarsson opened this issue Sep 6, 2018 · 0 comments
Labels

Comments

@JohanLarsson
Copy link
Collaborator

JohanLarsson commented Sep 6, 2018

        [Test]
        public void IsPatternBool()
        {
            var testCode = @"
namespace RoslynSandbox
{
    using System;
    using System.Globalization;
    using System.Windows;
    using System.Windows.Data;
    using System.Windows.Markup;

    [MarkupExtensionReturnType(typeof(BooleanToVisibilityConverterExtension))]
    [ValueConversion(typeof(bool?), typeof(Visibility))]
    public class BooleanToVisibilityConverterExtension : MarkupExtension, IValueConverter
    {
        public Visibility WhenTrue { get; set; }

        public Visibility WhenFalse { get; set; }

        public Visibility WhenNull { get; set; }

        public override object ProvideValue(IServiceProvider serviceProvider) => this;

        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool isTrue)
            {
                return isTrue
                    ? this.WhenTrue
                    : this.WhenFalse;
            }

            return this.WhenNull;
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}";
            AnalyzerAssert.Valid(Analyzer, testCode);
        }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant