Unlimited.Framework.Converters.Graph.String.Json.JsonMapper.BuildPath C# (CSharp) Method

BuildPath() private method

private BuildPath ( bool>.Stack propertyStack, JProperty jProperty, JToken root ) : IPath
propertyStack bool>.Stack
jProperty Newtonsoft.Json.Linq.JProperty
root JToken
return IPath
        private IPath BuildPath(Stack<Tuple<JProperty, bool>> propertyStack, JProperty jProperty, JToken root)
        {
            var path = new JsonPath();

            path.ActualPath = string.Join(JsonPath.SeperatorSymbol,
                propertyStack.Reverse().Select(p => path.CreatePathSegment(p.Item1).ToString(p.Item2)));

            List<Tuple<IPathSegment, bool>> displayPathSegments =
                propertyStack.Reverse()
                    .Select(p => new Tuple<IPathSegment, bool>(path.CreatePathSegment(p.Item1), p.Item2))
                    .ToList();
            bool recordsetEncountered = false;

            for (int i = displayPathSegments.Count - 1; i >= 0; i--)
            {
                Tuple<IPathSegment, bool> pathSegment = displayPathSegments[i];
                if (recordsetEncountered)
                {
                    pathSegment.Item1.IsEnumarable = false;
                }

                if (pathSegment.Item1.IsEnumarable && pathSegment.Item2) recordsetEncountered = true;
            }

            path.DisplayPath = string.Join(JsonPath.SeperatorSymbol,
                displayPathSegments.Select(p => p.Item1.ToString(p.Item2)));

            if (path.ActualPath != string.Empty)
            {
                path.ActualPath += JsonPath.SeperatorSymbol;
            }

            if (path.DisplayPath != string.Empty)
            {
                path.DisplayPath += JsonPath.SeperatorSymbol;
            }

            path.ActualPath += path.CreatePathSegment(jProperty).ToString();
            path.DisplayPath += path.CreatePathSegment(jProperty).ToString();
            path.SampleData += GetSampleData(root, path);

            return path;
        }