mirror of https://github.com/AMT-Cheif/Stylet.git
Keep ReSharper happy
This commit is contained in:
parent
3418fda5a2
commit
1fd12fd54b
|
@ -78,14 +78,7 @@ namespace Stylet
|
||||||
/// <param name="items">Items to manipulate</param>
|
/// <param name="items">Items to manipulate</param>
|
||||||
protected virtual void ActivateAndSetParent(IEnumerable items)
|
protected virtual void ActivateAndSetParent(IEnumerable items)
|
||||||
{
|
{
|
||||||
this.SetParent(items);
|
this.SetParentAndSetActive(items, this.IsActive);
|
||||||
foreach (var item in items)
|
|
||||||
{
|
|
||||||
if (this.IsActive)
|
|
||||||
ScreenExtensions.TryActivate(item);
|
|
||||||
else
|
|
||||||
ScreenExtensions.TryDeactivate(item);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -12,10 +12,17 @@ namespace Stylet
|
||||||
/// <typeparam name="T">Type of item to be conducted</typeparam>
|
/// <typeparam name="T">Type of item to be conducted</typeparam>
|
||||||
public abstract class ConductorBase<T> : Screen, IConductor<T>, IParent<T>, IChildDelegate where T : class
|
public abstract class ConductorBase<T> : Screen, IConductor<T>, IParent<T>, IChildDelegate where T : class
|
||||||
{
|
{
|
||||||
|
private bool _disposeChildren = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets a value indicating whether to dispose a child when it's closed. True by default
|
/// Gets or sets a value indicating whether to dispose a child when it's closed. True by default
|
||||||
/// </summary>
|
/// </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>
|
/// <summary>
|
||||||
/// Retrieves the Item or Items associated with this Conductor
|
/// Retrieves the Item or Items associated with this Conductor
|
||||||
|
@ -90,13 +97,5 @@ namespace Stylet
|
||||||
if (typedItem != null)
|
if (typedItem != null)
|
||||||
this.CloseItem(typedItem);
|
this.CloseItem(typedItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initialises a new instance of the <see cref="ConductorBase{T}"/> class
|
|
||||||
/// </summary>
|
|
||||||
public ConductorBase()
|
|
||||||
{
|
|
||||||
this.DisposeChildren = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ namespace Stylet
|
||||||
switch (e.Action)
|
switch (e.Action)
|
||||||
{
|
{
|
||||||
case NotifyCollectionChangedAction.Add:
|
case NotifyCollectionChangedAction.Add:
|
||||||
this.SetParent(e.NewItems);
|
this.SetParentAndSetActive(e.NewItems, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NotifyCollectionChangedAction.Remove:
|
case NotifyCollectionChangedAction.Remove:
|
||||||
|
@ -44,13 +44,13 @@ namespace Stylet
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NotifyCollectionChangedAction.Replace:
|
case NotifyCollectionChangedAction.Replace:
|
||||||
this.SetParent(e.NewItems);
|
this.SetParentAndSetActive(e.NewItems, false);
|
||||||
this.CloseAndCleanUp(e.OldItems, this.DisposeChildren);
|
this.CloseAndCleanUp(e.OldItems, this.DisposeChildren);
|
||||||
this.ActiveItemMayHaveBeenRemovedFromItems();
|
this.ActiveItemMayHaveBeenRemovedFromItems();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NotifyCollectionChangedAction.Reset:
|
case NotifyCollectionChangedAction.Reset:
|
||||||
this.SetParent(this.items);
|
this.SetParentAndSetActive(this.items, false);
|
||||||
this.ActiveItemMayHaveBeenRemovedFromItems();
|
this.ActiveItemMayHaveBeenRemovedFromItems();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,11 +17,19 @@ namespace Stylet
|
||||||
/// <typeparam name="T">Type of conductor</typeparam>
|
/// <typeparam name="T">Type of conductor</typeparam>
|
||||||
/// <param name="parent">Parent to set the items' parent to</param>
|
/// <param name="parent">Parent to set the items' parent to</param>
|
||||||
/// <param name="items">Items to manipulate</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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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))
|
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)))
|
.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
|
// Sadly, we can't cache this expression (I think), as it relies on the inputParameterExpression
|
||||||
// which is likely to change between calls
|
// 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,
|
// 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())
|
// and once for creating the implemtor (which is used in BuildUp())
|
||||||
if (!expressions.Any())
|
if (expressions.Count == 0)
|
||||||
return Expression.Empty();
|
return Expression.Empty();
|
||||||
return Expression.Block(expressions);
|
return Expression.Block(expressions);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,9 +54,10 @@ namespace StyletIoC.Internal.Builders
|
||||||
|
|
||||||
public IInScopeOrWithKeyOrAsWeakBinding ToAllImplementations(IEnumerable<Assembly> assemblies)
|
public IInScopeOrWithKeyOrAsWeakBinding ToAllImplementations(IEnumerable<Assembly> assemblies)
|
||||||
{
|
{
|
||||||
if (assemblies == null || !assemblies.Any())
|
var assembliesArray = (assemblies == null) ? new Assembly[0] : (assemblies as Assembly[] ?? assemblies.ToArray());
|
||||||
assemblies = new[] { Assembly.GetCallingAssembly() };
|
if (assembliesArray.Length == 0)
|
||||||
this.builderBinding = new BuilderToAllImplementationsBinding(this.ServiceType, assemblies);
|
assembliesArray = new[] { Assembly.GetCallingAssembly() };
|
||||||
|
this.builderBinding = new BuilderToAllImplementationsBinding(this.ServiceType, assembliesArray);
|
||||||
return this.builderBinding;
|
return this.builderBinding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -230,12 +230,13 @@ namespace StyletIoC
|
||||||
/// <param name="assemblies">Assembly(s) to search, or leave empty / null to search the current assembly</param>
|
/// <param name="assemblies">Assembly(s) to search, or leave empty / null to search the current assembly</param>
|
||||||
public void Autobind(IEnumerable<Assembly> assemblies)
|
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 they haven't given any assemblies, use the assembly of the caller
|
||||||
if (assemblies == null || !assemblies.Any())
|
if (assembliesArray.Length == 0)
|
||||||
assemblies = new[] { Assembly.GetCallingAssembly() };
|
assembliesArray = new[] { Assembly.GetCallingAssembly() };
|
||||||
|
|
||||||
// We self-bind concrete classes only
|
// 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)
|
foreach (var cls in classes)
|
||||||
{
|
{
|
||||||
// It's not actually possible for this to fail with a StyletIoCRegistrationException (at least currently)
|
// It's not actually possible for this to fail with a StyletIoCRegistrationException (at least currently)
|
||||||
|
|
|
@ -190,7 +190,7 @@ namespace Stylet
|
||||||
if (this.Validator == null)
|
if (this.Validator == null)
|
||||||
throw new InvalidOperationException("Can't run validation if a validator hasn't been set");
|
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);
|
return await this.ValidateAsync().ConfigureAwait(false);
|
||||||
|
|
||||||
// To allow synchronous calling of this method, we need to resume on the ThreadPool.
|
// To allow synchronous calling of this method, we need to resume on the ThreadPool.
|
||||||
|
|
|
@ -184,11 +184,16 @@ namespace StyletUnitTests
|
||||||
var screen2 = new Mock<IScreen>();
|
var screen2 = new Mock<IScreen>();
|
||||||
((IActivate)this.conductor).Activate();
|
((IActivate)this.conductor).Activate();
|
||||||
this.conductor.ActivateItem(screen1.Object);
|
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);
|
this.conductor.Items.Add(screen2.Object);
|
||||||
|
|
||||||
Assert.AreEqual(this.conductor.ActiveItem, screen1.Object);
|
Assert.AreEqual(this.conductor.ActiveItem, screen1.Object);
|
||||||
screen2.Verify(x => x.Activate(), Times.Never);
|
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]
|
[Test]
|
||||||
|
|
Loading…
Reference in New Issue