internal static bool TryIndex()

in src/PSRule.Rules.Azure/Data/Template/ExpressionHelpers.cs [160:193]


    internal static bool TryIndex(object o, object index, out object value)
    {
        value = null;
        if (o == null) return false;

        if (o is IMock mock)
        {
            value = mock.GetValue(index);
            return true;
        }

        if (TryArray(o, out var array) && TryConvertInt(index, out var arrayIndex))
        {
            if (array.Length <= arrayIndex)
                return false;

            value = array.GetValue(arrayIndex);
            return true;
        }

        if (o is JObject jObject && TryString(index, out var propertyName))
        {
            if (!jObject.TryGetValue(propertyName, StringComparison.OrdinalIgnoreCase, out var property))
                return false;

            value = property;
            return true;
        }

        if (o is ILazyObject lazy && TryConvertString(index, out var memberName) && lazy.TryProperty(memberName, out value))
            return true;

        return TryString(index, out propertyName) && TryPropertyOrField(o, propertyName, out value);
    }