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

INPC003 warns incorrectly about calculated property when ++ #224

Open
JohanLarsson opened this issue Oct 4, 2021 · 0 comments
Open

INPC003 warns incorrectly about calculated property when ++ #224

JohanLarsson opened this issue Oct 4, 2021 · 0 comments

Comments

@JohanLarsson
Copy link
Collaborator

    public sealed class SymbolLoadStatus : INotifyPropertyChanged
    {
        private static readonly int TotalCount = Database.GetAllSymbolKeys().Count();

        private string? displayText;
        private int processed;
        private DateTimeOffset? startTime;
        private DateTimeOffset? endTime;

        public event PropertyChangedEventHandler? PropertyChanged;

        public int Total => TotalCount;

        public TimeSpan? Elapsed => (this.EndTime ?? DateTimeOffset.Now) - this.startTime;

        public TimeSpan? Average => this.Elapsed / this.Processed;

        public string? DisplayText
        {
            get => this.displayText;
            private set
            {
                if (value == this.displayText)
                {
                    return;
                }

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

        public int Processed
        {
            get => this.processed;
            private set
            {
                if (value == this.processed)
                {
                    return;
                }

                this.processed = value;
                this.OnPropertyChanged();
                this.OnPropertyChanged(nameof(this.Average));
            }
        }

        public DateTimeOffset? StartTime
        {
            get => this.startTime;
            private set
            {
                if (value == this.startTime)
                {
                    return;
                }

                this.startTime = value;
                this.OnPropertyChanged();
                this.OnPropertyChanged(nameof(this.Elapsed));
                this.OnPropertyChanged(nameof(this.Average));
            }
        }

        public DateTimeOffset? EndTime
        {
            get => this.endTime;
            private set
            {
                if (value == this.endTime)
                {
                    return;
                }

                this.endTime = value;
                this.OnPropertyChanged();
                this.OnPropertyChanged(nameof(this.Elapsed));
                this.OnPropertyChanged(nameof(this.Average));
            }
        }

        public void Load(SymbolKey key)
        {
            if (this.startTime is null)
            {
                this.StartTime = DateTimeOffset.Now;
            }

            this.Processed++;
            this.DisplayText = $"Loading {this.processed} of {this.Total} in {this.Elapsed:mm\\:ss} average {this.Average?.TotalMilliseconds:F0} ms {key}";
        }

        private void OnPropertyChanged([CallerMemberName] string? propertyName = null)
        {
            this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant