in src/PSRule.Rules.Azure/Data/Template/ExpressionHelpers.cs [195:236]
internal static bool TryPropertyOrField(object o, string propertyName, out object value)
{
value = null;
if (IsNull(o)) return false;
var resultType = o.GetType();
if (o is IMock mock)
{
value = mock.GetValue(propertyName);
return true;
}
if (o is ILazyObject lazy && lazy.TryProperty(propertyName, out value))
return true;
if (o is JObject jObject)
{
if (!jObject.TryGetValue(propertyName, StringComparison.OrdinalIgnoreCase, out var propertyToken))
return false;
value = propertyToken;
return true;
}
if (o is JToken jToken && o is not JValue)
{
var propertyToken = jToken[propertyName];
if (propertyToken == null)
return false;
value = propertyToken.Value<object>();
return true;
}
// Try dictionary
if (o is IDictionary dictionary && dictionary.TryGetValue(propertyName, out value))
return true;
// Try property or field
return resultType.TryGetValue(o, propertyName, out value);
}