public static bool TryResolvePath()

in libraries/Microsoft.Bot.Builder.Dialogs/ObjectPath.cs [478:584]


        public static bool TryResolvePath(object obj, string propertyPath, out List<object> segments, bool eval = false)
        {
            var soFar = new List<object>();
            segments = soFar;
            var first = propertyPath.Length > 0 ? propertyPath[0] : ' ';
            if (first == '\'' || first == '"')
            {
                if (!propertyPath.EndsWith(first.ToString(), StringComparison.Ordinal))
                {
                    return false;
                }

                soFar.Add(propertyPath.Substring(1, propertyPath.Length - 2));
            }
            else if (int.TryParse(propertyPath, out var number))
            {
                soFar.Add(number);
            }
            else
            {
                var start = 0;
                int i;

                // Emit current fragment
                void Emit()
                {
                    var segment = propertyPath.Substring(start, i - start);
                    if (!string.IsNullOrEmpty(segment))
                    {
                        soFar.Add(segment);
                    }

                    start = i + 1;
                }

                // Scan path evaluating as we go
                for (i = 0; i < propertyPath.Length; ++i)
                {
                    var ch = propertyPath[i];
                    if (ch == '.' || ch == '[')
                    {
                        Emit();
                    }

                    if (ch == '[')
                    {
                        // Bracket expression
                        var nesting = 1;
                        while (++i < propertyPath.Length)
                        {
                            ch = propertyPath[i];
                            if (ch == '[')
                            {
                                ++nesting;
                            }
                            else if (ch == ']')
                            {
                                --nesting;
                                if (nesting == 0)
                                {
                                    break;
                                }
                            }
                        }

                        if (nesting > 0)
                        {
                            // Unbalanced brackets
                            return false;
                        }

                        var expr = propertyPath.Substring(start, i - start);
                        start = i + 1;
                        if (!TryResolvePath(obj, expr, out var indexer, true) || indexer.Count != 1)
                        {
                            // Could not resolve bracket expression
                            return false;
                        }

                        var result = MapValueTo<string>(indexer.First());
                        if (int.TryParse(result, out var index))
                        {
                            soFar.Add(index);
                        }
                        else
                        {
                            soFar.Add(result);
                        }
                    }
                }

                Emit();

                if (eval)
                {
                    if (!ResolveSegments(obj, soFar, out var result))
                    {
                        return false;
                    }

                    soFar.Clear();
                    soFar.Add(MapValueTo<string>(result));
                }
            }

            return true;
        }