Be draconian about using readonly where appropriate

This commit is contained in:
Antony Male 2014-12-04 17:06:12 +00:00
parent 91eab0958f
commit 94d4a31b85
11 changed files with 22 additions and 22 deletions

View File

@ -19,7 +19,7 @@ namespace Stylet
/// </summary>
public class AllActive : ConductorBase<T>
{
private BindableCollection<T> items = new BindableCollection<T>();
private readonly BindableCollection<T> items = new BindableCollection<T>();
/// <summary>
/// All items associated with this conductor

View File

@ -13,7 +13,7 @@ namespace Stylet
public class StackNavigation : ConductorBaseWithActiveItem<T>
{
// We need to remove arbitrary items, so no Stack<T> here!
private List<T> history = new List<T>();
private readonly List<T> history = new List<T>();
/// <summary>
/// Activate the given item. This deactivates the previous item, and pushes it onto the history stack

View File

@ -15,7 +15,7 @@ namespace Stylet
/// </summary>
public class OneActive : ConductorBaseWithActiveItem<T>
{
private BindableCollection<T> items = new BindableCollection<T>();
private readonly BindableCollection<T> items = new BindableCollection<T>();
/// <summary>
/// Items owned by this Conductor, one of which is active

View File

@ -123,7 +123,7 @@ namespace Stylet
{
private readonly WeakReference target;
private readonly List<HandlerInvoker> invokers = new List<HandlerInvoker>();
private HashSet<string> channels = new HashSet<string>();
private readonly HashSet<string> channels = new HashSet<string>();
public Handler(object handler, string[] channels)
{

View File

@ -29,7 +29,7 @@ namespace Stylet
/// <summary>
/// IModelValidator to use to validate properties. You're expected to write your own, using your favourite validation library
/// </summary>
protected virtual IModelValidator validator
protected virtual IModelValidator Validator
{
get { return this._validator; }
set
@ -98,7 +98,7 @@ namespace Stylet
/// <remarks>If you override this, you MUST fire ErrorsChanged as appropriate, and call ValidationStateChanged</remarks>
protected virtual async Task<bool> 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<string>();
await this.propertyErrorsLock.WaitAsync().ConfigureAwait(false);
{
@ -185,12 +185,12 @@ namespace Stylet
/// <remarks>If you override this, you MUST fire ErrorsChange and call OnValidationStateChanged() if appropriate</remarks>
protected virtual async Task<bool> 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);
}

View File

@ -8,7 +8,7 @@ namespace Stylet.Xaml
/// </summary>
public class ApplicationLoader : ResourceDictionary
{
private ResourceDictionary styletResourceDictionary;
private readonly ResourceDictionary styletResourceDictionary;
/// <summary>
/// Create a new ApplicationLoader instance

View File

@ -41,8 +41,8 @@ namespace Stylet.Xaml
private object target;
private ActionUnavailableBehaviour targetNullBehaviour;
private ActionUnavailableBehaviour actionNonExistentBehaviour;
private readonly ActionUnavailableBehaviour targetNullBehaviour;
private readonly ActionUnavailableBehaviour actionNonExistentBehaviour;
/// <summary>
/// Create a new ActionCommand

View File

@ -35,8 +35,8 @@ namespace Stylet.Xaml
private object target;
private ActionUnavailableBehaviour targetNullBehaviour;
private ActionUnavailableBehaviour actionNonExistentBehaviour;
private readonly ActionUnavailableBehaviour targetNullBehaviour;
private readonly ActionUnavailableBehaviour actionNonExistentBehaviour;
/// <summary>
/// Create a new EventAction

View File

@ -15,7 +15,7 @@ namespace Stylet.Xaml
/// <summary>
/// Singleton instance of this converter. Usage e.g. Converter="{x:Static s:IconToBitmapSourceConverter.Instance}"
/// </summary>
public static IconToBitmapSourceConverter Instance = new IconToBitmapSourceConverter();
public static readonly IconToBitmapSourceConverter Instance = new IconToBitmapSourceConverter();
/// <summary>
/// Converts a value

View File

@ -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() { }

View File

@ -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()