NodeExtensions
using Relativity.DataTransfer.Nodes;
using System;
using System.Text;
namespace Relativity.Transfer.Paths
{
public static class NodeExtensions
{
public static string FindRelativePath(this INode rootNode, INode node)
{
if (!rootNode.Context.Equals(node.Context))
throw new ArgumentException("Nodes come from different contexts - it can be impossible to determine a relative path between them", "node");
INode node2 = node;
StringBuilder stringBuilder = new StringBuilder();
while (node2?.Parent != null && !node2.Parent.Equals(rootNode)) {
stringBuilder.Insert(0, node2.Parent.Name + PathConstants.DirectorySeparatorAsString);
node2 = node2.Parent;
}
if (stringBuilder.Length == 0)
return string.Empty;
stringBuilder.Remove(stringBuilder.Length - 1, 1);
if (node2?.Parent == null)
return null;
return stringBuilder.ToString();
}
}
}