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

Fixes for INPC002 when static #169

Open
JohanLarsson opened this issue Jan 19, 2020 · 4 comments
Open

Fixes for INPC002 when static #169

JohanLarsson opened this issue Jan 19, 2020 · 4 comments

Comments

@JohanLarsson
Copy link
Collaborator

Not extremely useful as binding to static properties is rare.

@JohanLarsson
Copy link
Collaborator Author

        [Test]
        public static void StaticEventHandlerOfPropertyChangedEventArgsInvoke()
        {
            var before = @"
namespace N
{
    using System;
    using System.ComponentModel;

    public static class C
    {
        public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;

        public static string ↓P { get; set; }
    }
}";

            var after = @"
namespace N
{
    using System;
    using System.ComponentModel;

    public static class C
    {
        private static string p;

        public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;

        public static string P
        {
            get => p;
            set
            {
                if (value == p)
                {
                    return;
                }

                p = value;
                StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(P)));
            }
        }
    }
}";
            RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after);
        }

@JohanLarsson
Copy link
Collaborator Author

        [Test]
        public static void StaticEventHandlerOfPropertyChangedEventArgsInvoker()
        {
            var before = @"
namespace N
{
    using System;
    using System.ComponentModel;

    public static class C
    {
        public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;

        public static string ↓P { get; set; }

        private static void OnStaticPropertyChanged(string propertyName)
        {
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
        }
    }
}";

            var after = @"
namespace N
{
    using System;
    using System.ComponentModel;

    public static class C
    {
        private static string p;

        public static event EventHandler<PropertyChangedEventArgs> StaticPropertyChanged;

        public static string P
        {
            get => p;
            set
            {
                if (value == p)
                {
                    return;
                }

                p = value;
                OnStaticPropertyChanged(nameof(P));
            }
        }

        private static void OnStaticPropertyChanged(string propertyName)
        {
            StaticPropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
        }
    }
}";
            RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after);
        }

@JohanLarsson
Copy link
Collaborator Author

        [Test]
        public static void StaticPropertyChangedEventHandlerInvoke()
        {
            var before = @"
namespace N
{
    using System.ComponentModel;

    public class C
    {
        public static event PropertyChangedEventHandler PropertyChanged;

        public static string ↓P { get; set; }
    }
}";

            var after = @"
namespace N
{
    using System.ComponentModel;

    public class C
    {
        private static string p;

        public static event PropertyChangedEventHandler PropertyChanged;

        public static string P
        {
            get => p;
            set
            {
                if (value == p)
                {
                    return;
                }

                p = value;
                PropertyChanged?.Invoke(null, new PropertyChangedEventArgs(nameof(P)));
            }
        }
    }
}";
            RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after);
        }

@JohanLarsson
Copy link
Collaborator Author

        [Test]
        public static void StaticPropertyChangedEventHandlerInvoker()
        {
            var before = @"
namespace N
{
    using System.ComponentModel;

    public class C
    {
        public static event PropertyChangedEventHandler PropertyChanged;

        public static string ↓P { get; set; }

        private static void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
        }
    }
}";

            var after = @"
namespace N
{
    using System.ComponentModel;

    public class C
    {
        private static string p;

        public static event PropertyChangedEventHandler PropertyChanged;

        public static string P
        {
            get => p;
            set
            {
                if (value == p)
                {
                    return;
                }

                p = value;
                OnPropertyChanged(nameof(P));
            }
        }

        private static void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(null, new PropertyChangedEventArgs(propertyName));
        }
    }
}";
            RoslynAssert.CodeFix(Analyzer, Fix, ExpectedDiagnostic, before, after);
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant