Skip to content

Commit

Permalink
Refactor visibility code
Browse files Browse the repository at this point in the history
References #33
  • Loading branch information
andreashuber-lawo committed Feb 9, 2017
1 parent 72cbc74 commit 704a320
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 36 deletions.
1 change: 1 addition & 0 deletions Lawo.EmberPlusSharp/Lawo.EmberPlusSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
<Compile Include="Model\IParent.cs" />
<Compile Include="Model\ValueWriter`1.cs" />
<Compile Include="Model\ValueReader`1.cs" />
<Compile Include="Model\VisibilityHelper.cs" />
<Compile Include="S101\EventInfo.cs" />
<Compile Include="S101\LogNames.cs" />
<Compile Include="Glow\GlowLogConverter.cs" />
Expand Down
14 changes: 1 addition & 13 deletions Lawo.EmberPlusSharp/Model/CollectionNode`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,7 @@ internal sealed override bool ChangeVisibility(IElement child)
{
if (!base.ChangeVisibility(child))
{
if (child.IsOnline)
{
var typedChild = (TElement)child;

if (!this.children.Contains(typedChild))
{
this.children.Add(typedChild);
}
}
else
{
this.children.Remove((TElement)child);
}
VisibilityHelper.ChangeVisibility(this.children, (TElement)child);
}

return true;
Expand Down
12 changes: 1 addition & 11 deletions Lawo.EmberPlusSharp/Model/DynamicNodeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,7 @@ internal static bool ChangeVisibility(
{
if (!baseImpl(child))
{
if (child.IsOnline)
{
if (!dynamicChildren.Contains(child))
{
dynamicChildren.Add(child);
}
}
else
{
dynamicChildren.Remove(child);
}
VisibilityHelper.ChangeVisibility(dynamicChildren, child);
}

return true;
Expand Down
13 changes: 1 addition & 12 deletions Lawo.EmberPlusSharp/Model/Node`1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,7 @@ internal Node()
[SuppressMessage("Microsoft.Design", "CA1062:Validate arguments of public methods", Justification = "Method is not public, CA bug?")]
internal override bool ChangeVisibility(IElement child)
{
if (child.IsOnline)
{
if (!this.observableChildren.Contains(child))
{
this.observableChildren.Add(child);
}
}
else
{
this.observableChildren.Remove(child);
}

VisibilityHelper.ChangeVisibility(this.observableChildren, child);
return base.ChangeVisibility(child);
}

Expand Down
29 changes: 29 additions & 0 deletions Lawo.EmberPlusSharp/Model/VisibilityHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// <copyright>Copyright 2012-2017 Lawo AG (http://www.lawo.com).</copyright>
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace Lawo.EmberPlusSharp.Model
{
using System.Collections.Generic;

internal static class VisibilityHelper
{
internal static void ChangeVisibility<T>(ICollection<T> children, T child)
where T : IElement
{
if (child.IsOnline)
{
if (!children.Contains(child))
{
children.Add(child);
}
}
else
{
children.Remove(child);
}
}
}
}

0 comments on commit 704a320

Please sign in to comment.