Browse Source

Added logical tree extension methods.

pull/39/head
Steven Kirk 11 years ago
parent
commit
89e8871e90
  1. 80
      Perspex.SceneGraph/LogicalTree/LogicalExtensions.cs
  2. 1
      Perspex.SceneGraph/Perspex.SceneGraph.csproj

80
Perspex.SceneGraph/LogicalTree/LogicalExtensions.cs

@ -0,0 +1,80 @@
// -----------------------------------------------------------------------
// <copyright file="LogicalExtensions.cs" company="Steven Kirk">
// Copyright 2014 MIT Licence. See licence.md for more information.
// </copyright>
// -----------------------------------------------------------------------
namespace Perspex.LogicalTree
{
using System;
using System.Collections.Generic;
using System.Linq;
public static class LogicalExtensions
{
public static IEnumerable<ILogical> GetLogicalAncestors(this ILogical logical)
{
Contract.Requires<NullReferenceException>(logical != null);
logical = logical.LogicalParent;
while (logical != null)
{
yield return logical;
logical = logical.LogicalParent;
}
}
public static IEnumerable<ILogical> GetSelfAndLogicalAncestors(this ILogical logical)
{
yield return logical;
foreach (var ancestor in logical.GetLogicalAncestors())
{
yield return ancestor;
}
}
public static IEnumerable<ILogical> GetLogicalChildren(this ILogical logical)
{
return logical.LogicalChildren;
}
public static IEnumerable<ILogical> GetLogicalDescendents(this ILogical logical)
{
foreach (ILogical child in logical.LogicalChildren)
{
yield return child;
foreach (ILogical descendent in child.GetLogicalDescendents())
{
yield return descendent;
}
}
}
public static ILogical GetLogicalParent(this ILogical logical)
{
return logical.LogicalParent;
}
public static T GetLogicalParent<T>(this ILogical logical) where T : class
{
return logical.LogicalParent as T;
}
public static IEnumerable<ILogical> GetLogicalSiblings(this ILogical logical)
{
ILogical parent = logical.LogicalParent;
if (parent != null)
{
foreach (ILogical sibling in parent.LogicalChildren)
{
yield return sibling;
}
}
}
}
}

1
Perspex.SceneGraph/Perspex.SceneGraph.csproj

@ -92,6 +92,7 @@
<Compile Include="Thickness.cs" /> <Compile Include="Thickness.cs" />
<Compile Include="Vector.cs" /> <Compile Include="Vector.cs" />
<Compile Include="Visual.cs" /> <Compile Include="Visual.cs" />
<Compile Include="LogicalTree\LogicalExtensions.cs" />
<Compile Include="VisualTree\VisualExtensions.cs" /> <Compile Include="VisualTree\VisualExtensions.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

Loading…
Cancel
Save