diff --git a/Stylet/ConductorAllActive.cs b/Stylet/ConductorAllActive.cs index 4d22401..b6c2470 100644 --- a/Stylet/ConductorAllActive.cs +++ b/Stylet/ConductorAllActive.cs @@ -19,7 +19,7 @@ namespace Stylet /// public class AllActive : ConductorBase { - private BindableCollection items = new BindableCollection(); + private readonly BindableCollection items = new BindableCollection(); /// /// All items associated with this conductor diff --git a/Stylet/ConductorNavigating.cs b/Stylet/ConductorNavigating.cs index 95872c3..b530699 100644 --- a/Stylet/ConductorNavigating.cs +++ b/Stylet/ConductorNavigating.cs @@ -13,7 +13,7 @@ namespace Stylet public class StackNavigation : ConductorBaseWithActiveItem { // We need to remove arbitrary items, so no Stack here! - private List history = new List(); + private readonly List history = new List(); /// /// Activate the given item. This deactivates the previous item, and pushes it onto the history stack diff --git a/Stylet/ConductorOneActive.cs b/Stylet/ConductorOneActive.cs index 28d05e2..c0bb6e8 100644 --- a/Stylet/ConductorOneActive.cs +++ b/Stylet/ConductorOneActive.cs @@ -15,7 +15,7 @@ namespace Stylet /// public class OneActive : ConductorBaseWithActiveItem { - private BindableCollection items = new BindableCollection(); + private readonly BindableCollection items = new BindableCollection(); /// /// Items owned by this Conductor, one of which is active diff --git a/Stylet/EventAggregator.cs b/Stylet/EventAggregator.cs index 2ec06c7..d636134 100644 --- a/Stylet/EventAggregator.cs +++ b/Stylet/EventAggregator.cs @@ -123,7 +123,7 @@ namespace Stylet { private readonly WeakReference target; private readonly List invokers = new List(); - private HashSet channels = new HashSet(); + private readonly HashSet channels = new HashSet(); public Handler(object handler, string[] channels) { diff --git a/Stylet/ValidatingModelBase.cs b/Stylet/ValidatingModelBase.cs index 8e3af3c..fced083 100644 --- a/Stylet/ValidatingModelBase.cs +++ b/Stylet/ValidatingModelBase.cs @@ -29,7 +29,7 @@ namespace Stylet /// /// IModelValidator to use to validate properties. You're expected to write your own, using your favourite validation library /// - protected virtual IModelValidator validator + protected virtual IModelValidator Validator { get { return this._validator; } set @@ -98,7 +98,7 @@ namespace Stylet /// If you override this, you MUST fire ErrorsChanged as appropriate, and call ValidationStateChanged protected virtual async Task ValidateAsync() { - if (this.validator == null) + if (this.Validator == null) throw new InvalidOperationException("Can't run validation if a validator hasn't been set"); bool anyChanged = false; @@ -107,7 +107,7 @@ namespace Stylet // However this means that the stuff after the await can be run in parallel on multiple threads // Therefore, we need the lock // However, we can't raise PropertyChanged events from within the lock, otherwise deadlock - var results = await this.validator.ValidateAllPropertiesAsync().ConfigureAwait(false); + var results = await this.Validator.ValidateAllPropertiesAsync().ConfigureAwait(false); var changedProperties = new List(); await this.propertyErrorsLock.WaitAsync().ConfigureAwait(false); { @@ -185,12 +185,12 @@ namespace Stylet /// If you override this, you MUST fire ErrorsChange and call OnValidationStateChanged() if appropriate protected virtual async Task ValidatePropertyAsync([CallerMemberName] string propertyName = null) { - if (this.validator == null) + if (this.Validator == null) throw new InvalidOperationException("Can't run validation if a validator hasn't been set"); // To allow synchronous calling of this method, we need to resume on the ThreadPool. // Therefore, we might resume on any thread, hence the need for a lock - var newErrors = await this.validator.ValidatePropertyAsync(propertyName).ConfigureAwait(false); + var newErrors = await this.Validator.ValidatePropertyAsync(propertyName).ConfigureAwait(false); bool propertyErrorsChanged = false; await this.propertyErrorsLock.WaitAsync().ConfigureAwait(false); @@ -222,7 +222,7 @@ namespace Stylet // Save ourselves a little bit of work every time HasErrors is fired as the result of // the validation results changing. - if (this.validator != null && this.AutoValidate && propertyName != "HasErrors") + if (this.Validator != null && this.AutoValidate && propertyName != "HasErrors") await this.ValidatePropertyAsync(propertyName); } diff --git a/Stylet/Xaml/ApplicationLoader.cs b/Stylet/Xaml/ApplicationLoader.cs index d6f4b0d..b9e6a78 100644 --- a/Stylet/Xaml/ApplicationLoader.cs +++ b/Stylet/Xaml/ApplicationLoader.cs @@ -8,7 +8,7 @@ namespace Stylet.Xaml /// public class ApplicationLoader : ResourceDictionary { - private ResourceDictionary styletResourceDictionary; + private readonly ResourceDictionary styletResourceDictionary; /// /// Create a new ApplicationLoader instance diff --git a/Stylet/Xaml/CommandAction.cs b/Stylet/Xaml/CommandAction.cs index 47b0d8d..a9e7c42 100644 --- a/Stylet/Xaml/CommandAction.cs +++ b/Stylet/Xaml/CommandAction.cs @@ -41,8 +41,8 @@ namespace Stylet.Xaml private object target; - private ActionUnavailableBehaviour targetNullBehaviour; - private ActionUnavailableBehaviour actionNonExistentBehaviour; + private readonly ActionUnavailableBehaviour targetNullBehaviour; + private readonly ActionUnavailableBehaviour actionNonExistentBehaviour; /// /// Create a new ActionCommand diff --git a/Stylet/Xaml/EventAction.cs b/Stylet/Xaml/EventAction.cs index 50df439..c5ae6e7 100644 --- a/Stylet/Xaml/EventAction.cs +++ b/Stylet/Xaml/EventAction.cs @@ -35,8 +35,8 @@ namespace Stylet.Xaml private object target; - private ActionUnavailableBehaviour targetNullBehaviour; - private ActionUnavailableBehaviour actionNonExistentBehaviour; + private readonly ActionUnavailableBehaviour targetNullBehaviour; + private readonly ActionUnavailableBehaviour actionNonExistentBehaviour; /// /// Create a new EventAction diff --git a/Stylet/Xaml/IconToBitmapSourceConverter.cs b/Stylet/Xaml/IconToBitmapSourceConverter.cs index 865bb25..38058d1 100644 --- a/Stylet/Xaml/IconToBitmapSourceConverter.cs +++ b/Stylet/Xaml/IconToBitmapSourceConverter.cs @@ -15,7 +15,7 @@ namespace Stylet.Xaml /// /// Singleton instance of this converter. Usage e.g. Converter="{x:Static s:IconToBitmapSourceConverter.Instance}" /// - public static IconToBitmapSourceConverter Instance = new IconToBitmapSourceConverter(); + public static readonly IconToBitmapSourceConverter Instance = new IconToBitmapSourceConverter(); /// /// Converts a value diff --git a/StyletUnitTests/ScreenTests.cs b/StyletUnitTests/ScreenTests.cs index ddf7584..3c587ab 100644 --- a/StyletUnitTests/ScreenTests.cs +++ b/StyletUnitTests/ScreenTests.cs @@ -17,10 +17,10 @@ namespace StyletUnitTests { private class MyScreen : Screen { - public IModelValidator Validator + public new IModelValidator Validator { - get { return base.validator; } - set { base.validator = value; } + get { return base.Validator; } + set { base.Validator = value; } } public MyScreen() { } diff --git a/StyletUnitTests/ValidatingModelBaseTests.cs b/StyletUnitTests/ValidatingModelBaseTests.cs index 74a3800..b0c4cfb 100644 --- a/StyletUnitTests/ValidatingModelBaseTests.cs +++ b/StyletUnitTests/ValidatingModelBaseTests.cs @@ -31,10 +31,10 @@ namespace StyletUnitTests set { base.AutoValidate = value; } } - public IModelValidator Validator + public new IModelValidator Validator { - get { return this.validator; } - set { this.validator = value; } + get { return base.Validator; } + set { base.Validator = value; } } public new bool Validate()