<commit_before>﻿using System;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace GUtils.MVVM
{
    /// <summary>
    /// Implements a few utility functions for a ViewModel base
    /// </summary>
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        /// <inheritdoc/>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Does the logic for calling <see cref="PropertyChanged"/> if the value has changed (and
        /// also sets the value of the field)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="field"></param>
        /// <param name="newValue"></param>
        /// <param name="propertyName"></param>
        [MethodImpl ( MethodImplOptions.NoInlining )]
        protected virtual void SetField<T> ( ref T field, T newValue, [CallerMemberName] String propertyName = null )
        {
            if ( field.Equals ( newValue ) )
                return;
            field = newValue;
            this.OnPropertyChanged ( propertyName );
        }

        /// <summary>
        /// Invokes <see cref="PropertyChanged"/>
        /// </summary>
        /// <param name="propertyName"></param>
        /// <exception cref="ArgumentNullException">
        /// Invoked if a <paramref name="propertyName"/> is not provided (and the value isn't
        /// auto-filled by the compiler)
        /// </exception>
        [MethodImpl ( MethodImplOptions.NoInlining )]
        protected virtual void OnPropertyChanged ( [CallerMemberName] String propertyName = null ) =>
            this.PropertyChanged?.Invoke (
                this,<commit_msg>Fix the possibility of a NullReferenceException<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.CompilerServices;

namespace GUtils.MVVM
{
    /// <summary>
    /// Implements a few utility functions for a ViewModel base
    /// </summary>
    public abstract class ViewModelBase : INotifyPropertyChanged
    {
        /// <inheritdoc/>
        public event PropertyChangedEventHandler PropertyChanged;

        /// <summary>
        /// Does the logic for calling <see cref="PropertyChanged"/> if the value has changed (and
        /// also sets the value of the field)
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="field"></param>
        /// <param name="newValue"></param>
        /// <param name="propertyName"></param>
        [MethodImpl ( MethodImplOptions.NoInlining )]
        protected virtual void SetField<T> ( ref T field, T newValue, [CallerMemberName] String propertyName = null )
        {
            if ( EqualityComparer<T>.Default.Equals ( field, newValue ) )
                return;
            field = newValue;
            this.OnPropertyChanged ( propertyName );
        }

        /// <summary>
        /// Invokes <see cref="PropertyChanged"/>
        /// </summary>
        /// <param name="propertyName"></param>
        /// <exception cref="ArgumentNullException">
        /// Invoked if a <paramref name="propertyName"/> is not provided (and the value isn't
        /// auto-filled by the compiler)
        /// </exception>
        [MethodImpl ( MethodImplOptions.NoInlining )]
        protected virtual void OnPropertyChanged ( [CallerMemberName] String propertyName = null ) =>
            this.PropertyChanged?.Invoke (
                this,
{'fraction_non_alphanumeric': 0.12287769784172661, 'fraction_numerical': 0.0, 'mean_word_length': 2.1715328467153285, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 52, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1977447', 'n_tokens_mistral': 865, 'n_tokens_neox': 854, 'n_words': 247}