Keep ReSharper happy

This commit is contained in:
Antony Male 2015-01-15 10:35:27 +00:00
parent 3418fda5a2
commit 1fd12fd54b
9 changed files with 41 additions and 33 deletions

View File

@ -78,14 +78,7 @@ namespace Stylet
/// <param name="items">Items to manipulate</param>
protected virtual void ActivateAndSetParent(IEnumerable items)
{
this.SetParent(items);
foreach (var item in items)
{
if (this.IsActive)
ScreenExtensions.TryActivate(item);
else
ScreenExtensions.TryDeactivate(item);
}
this.SetParentAndSetActive(items, this.IsActive);
}
/// <summary>

View File

@ -12,10 +12,17 @@ namespace Stylet
/// <typeparam name="T">Type of item to be conducted</typeparam>
public abstract class ConductorBase<T> : Screen, IConductor<T>, IParent<T>, IChildDelegate where T : class
{
private bool _disposeChildren = true;
/// <summary>
/// Gets or sets a value indicating whether to dispose a child when it's closed. True by default
/// </summary>
public virtual bool DisposeChildren { get; set; }
// Can't be an auto-property, since it's virtual so we can't set it in the ctor
public virtual bool DisposeChildren
{
get { return this._disposeChildren; }
set { this._disposeChildren = value; }
}
/// <summary>
/// Retrieves the Item or Items associated with this Conductor
@ -90,13 +97,5 @@ namespace Stylet
if (typedItem != null)
this.CloseItem(typedItem);
}
/// <summary>
/// Initialises a new instance of the <see cref="ConductorBase{T}"/> class
/// </summary>
public ConductorBase()
{
this.DisposeChildren = true;
}
}
}

View File

@ -35,7 +35,7 @@ namespace Stylet
switch (e.Action)
{
case NotifyCollectionChangedAction.Add:
this.SetParent(e.NewItems);
this.SetParentAndSetActive(e.NewItems, false);
break;
case NotifyCollectionChangedAction.Remove:
@ -44,13 +44,13 @@ namespace Stylet
break;
case NotifyCollectionChangedAction.Replace:
this.SetParent(e.NewItems);
this.SetParentAndSetActive(e.NewItems, false);
this.CloseAndCleanUp(e.OldItems, this.DisposeChildren);
this.ActiveItemMayHaveBeenRemovedFromItems();
break;
case NotifyCollectionChangedAction.Reset:
this.SetParent(this.items);
this.SetParentAndSetActive(this.items, false);
this.ActiveItemMayHaveBeenRemovedFromItems();
break;
}

View File

@ -17,11 +17,19 @@ namespace Stylet
/// <typeparam name="T">Type of conductor</typeparam>
/// <param name="parent">Parent to set the items' parent to</param>
/// <param name="items">Items to manipulate</param>
public static void SetParent<T>(this IConductor<T> parent, IEnumerable items)
/// <param name="active">True to active the item, false to deactive it</param>
public static void SetParentAndSetActive<T>(this IConductor<T> parent, IEnumerable items, bool active)
{
foreach (var child in items.OfType<IChild>())
foreach (var item in items)
{
child.Parent = parent;
var itemAsChild = item as IChild;
if (itemAsChild != null)
itemAsChild.Parent = parent;
if (active)
ScreenExtensions.TryActivate(item);
else
ScreenExtensions.TryDeactivate(item);
}
}

View File

@ -36,13 +36,14 @@ namespace StyletIoC.Creation
{
var expressions = this.type.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Select(x => this.ExpressionForMember(inputParameterExpression, x, x.FieldType, registrationContext))
.Concat(this.type.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).Select(x => this.ExpressionForMember(inputParameterExpression, x, x.PropertyType, registrationContext)))
.Where(x => x != null);
.Where(x => x != null)
.ToList();
// Sadly, we can't cache this expression (I think), as it relies on the inputParameterExpression
// which is likely to change between calls
// This isn't so bad, so we'll (probably) only need to call this at most twice - once for building up the type on creation,
// and once for creating the implemtor (which is used in BuildUp())
if (!expressions.Any())
if (expressions.Count == 0)
return Expression.Empty();
return Expression.Block(expressions);
}

View File

@ -54,9 +54,10 @@ namespace StyletIoC.Internal.Builders
public IInScopeOrWithKeyOrAsWeakBinding ToAllImplementations(IEnumerable<Assembly> assemblies)
{
if (assemblies == null || !assemblies.Any())
assemblies = new[] { Assembly.GetCallingAssembly() };
this.builderBinding = new BuilderToAllImplementationsBinding(this.ServiceType, assemblies);
var assembliesArray = (assemblies == null) ? new Assembly[0] : (assemblies as Assembly[] ?? assemblies.ToArray());
if (assembliesArray.Length == 0)
assembliesArray = new[] { Assembly.GetCallingAssembly() };
this.builderBinding = new BuilderToAllImplementationsBinding(this.ServiceType, assembliesArray);
return this.builderBinding;
}

View File

@ -230,12 +230,13 @@ namespace StyletIoC
/// <param name="assemblies">Assembly(s) to search, or leave empty / null to search the current assembly</param>
public void Autobind(IEnumerable<Assembly> assemblies)
{
var assembliesArray = (assemblies == null) ? new Assembly[0] : (assemblies as Assembly[] ?? assemblies.ToArray());
// If they haven't given any assemblies, use the assembly of the caller
if (assemblies == null || !assemblies.Any())
assemblies = new[] { Assembly.GetCallingAssembly() };
if (assembliesArray.Length == 0)
assembliesArray = new[] { Assembly.GetCallingAssembly() };
// We self-bind concrete classes only
var classes = assemblies.Distinct().SelectMany(x => x.GetTypes()).Where(c => c.IsClass && !c.IsAbstract);
var classes = assembliesArray.Distinct().SelectMany(x => x.GetTypes()).Where(c => c.IsClass && !c.IsAbstract);
foreach (var cls in classes)
{
// It's not actually possible for this to fail with a StyletIoCRegistrationException (at least currently)

View File

@ -190,7 +190,7 @@ namespace Stylet
if (this.Validator == null)
throw new InvalidOperationException("Can't run validation if a validator hasn't been set");
if (propertyName == null || propertyName == String.Empty)
if (String.IsNullOrEmpty(propertyName))
return await this.ValidateAsync().ConfigureAwait(false);
// To allow synchronous calling of this method, we need to resume on the ThreadPool.

View File

@ -184,11 +184,16 @@ namespace StyletUnitTests
var screen2 = new Mock<IScreen>();
((IActivate)this.conductor).Activate();
this.conductor.ActivateItem(screen1.Object);
// This is an implementation detail
screen1.Verify(x => x.Deactivate(), Times.Once);
screen1.Verify(x => x.Activate(), Times.Once);
this.conductor.Items.Add(screen2.Object);
Assert.AreEqual(this.conductor.ActiveItem, screen1.Object);
screen2.Verify(x => x.Activate(), Times.Never);
screen1.Verify(x => x.Deactivate(), Times.Never);
screen1.Verify(x => x.Deactivate(), Times.Once); // The one deactivate from earlier
}
[Test]