Ejemplo n.º 1
0
            public static void AutoPropertyToTrySetStyleDetection(AutoDetectedStyle style)
            {
                var before = @"
namespace N
{
    public class C : Caliburn.Micro.Screen
    {
        public int ↓P { get; set; }
    }
}";

                var after = @"
namespace N
{
    public class C : Caliburn.Micro.Screen
    {
        private int p;

        public int P { get => this.p; set => Set(ref this.p, value); }
    }
}";

                RoslynAssert.CodeFix(
                    Analyzer,
                    Fix,
                    ExpectedDiagnostic,
                    new[] { style.AdditionalSample, before },
                    style.Apply(after, "p"),
                    fixTitle: "Set(ref oldValue, newValue)",
                    metadataReferences: MetadataReferences);
            }
Ejemplo n.º 2
0
        public static void WhenNotNotifyingWithBackingFieldStyleDetection(AutoDetectedStyle style)
        {
            var before = @"
namespace N
{
    public class ↓C
    {
        private int p;

        public int P
        {
            get
            {
                return this.p;
            }
            private set
            {
                this.p = value;
            }
        }
    }
}";

            var after = @"
namespace N
{
    public class C : System.ComponentModel.INotifyPropertyChanged
    {
        private int p;

        public event System.ComponentModel.PropertyChangedEventHandler PropertyChanged;

        public int P
        {
            get
            {
                return this.p;
            }
            private set
            {
                this.p = value;
            }
        }

        protected virtual void OnPropertyChanged([System.Runtime.CompilerServices.CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
        }
    }
}";

            RoslynAssert.CodeFix(
                Analyzer,
                Fix,
                ExpectedDiagnostic,
                new[] { style.AdditionalSample, style.Apply(before, "p") },
                style.Apply(after, "p"),
                fixTitle: "Implement INotifyPropertyChanged fully qualified.");
        }
Ejemplo n.º 3
0
            public static void WithBackingFieldToSetExpressionBodyStyleDetection(AutoDetectedStyle style)
            {
                var before = @"
namespace N
{
    public class C : Caliburn.Micro.Screen
    {
        private string name;

        public string ↓Name
        {
            get => this.name;
            set => this.name = value;
        }
    }
}";

                var after = @"
namespace N
{
    public class C : Caliburn.Micro.Screen
    {
        private string name;

        public string Name
        {
            get => this.name;
            set => Set(ref this.name, value);
        }
    }
}";

                RoslynAssert.CodeFix(
                    Analyzer,
                    Fix,
                    ExpectedDiagnostic,
                    new[] { style.AdditionalSample, before },
                    after,
                    fixTitle: "Set(ref oldValue, newValue)",
                    metadataReferences: MetadataReferences);
            }
            public static void WithBackingFieldToSetStatementBodyStyleDetection(AutoDetectedStyle style)
            {
                var before = @"
namespace N
{
    public class C : Caliburn.Micro.PropertyChangedBase
    {
        private string name;

        public string ↓Name
        {
            get { return this.name; }
            set { this.name = value; }
        }
    }
}";

                var after = @"
namespace N
{
    public class C : Caliburn.Micro.PropertyChangedBase
    {
        private string name;

        public string Name
        {
            get { return this.name; }
            set { Set(ref this.name, value); }
        }
    }
}";

                RoslynAssert.CodeFix(
                    Analyzer,
                    Fix,
                    ExpectedDiagnostic,
                    new[] { style.AdditionalSample, style.Apply(before, "name") },
                    style.Apply(after, "name"),
                    fixTitle: "Set(ref oldValue, newValue)",
                    metadataReferences: MetadataReferences);
            }
            public static void WhenInterfaceOnlyWithUsingAddUsingsStyleDetection(AutoDetectedStyle style)
            {
                var before = @"
#pragma warning disable 169
namespace N
{
    using System.ComponentModel;

    public class C : ↓INotifyPropertyChanged
    {
        private int p;
    }
}";

                var after = @"
#pragma warning disable 169
namespace N
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    public class C : INotifyPropertyChanged
    {
        private int p;

        public event PropertyChangedEventHandler PropertyChanged;

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}";

                RoslynAssert.CodeFix(
                    Fix,
                    ExpectedDiagnostic,
                    new[] { style.AdditionalSample, style.Apply(before, "p") },
                    style.Apply(after, "p"),
                    fixTitle: "Implement INotifyPropertyChanged and add usings.");
            }
Ejemplo n.º 6
0
            public static void CallerMemberNameStyleDetection(AutoDetectedStyle style)
            {
                var before = @"
namespace N
{
    using System.ComponentModel;
    using System.Runtime.CompilerServices;

    public class C : INotifyPropertyChanged
    {
        private readonly int p1;

        public event PropertyChangedEventHandler PropertyChanged;

        public int P1 => this.p1;

        public int ↓P2 { get; set; }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}";

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

    public class C : INotifyPropertyChanged
    {
        private readonly int p1;
        private int p2;

        public event PropertyChangedEventHandler PropertyChanged;

        public int P1 => this.p1;

        public int P2
        {
            get => this.p2;
            set
            {
                if (value == this.p2)
                {
                    return;
                }

                this.p2 = value;
                OnPropertyChanged();
            }
        }

        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
}";

                RoslynAssert.CodeFix(
                    Analyzer,
                    Fix,
                    ExpectedDiagnostic,
                    new[] { style.AdditionalSample, style.Apply(before, "p1") },
                    style.Apply(after, "p1", "p2"));
            }