/// <inheritdoc /> public bool TryGetValue <T>(IPublishedElement content, string alias, string?culture, string?segment, Fallback fallback, T?defaultValue, out T?value) { var propertyType = content.ContentType.GetPropertyType(alias); if (propertyType == null) { value = default; return(false); } _variationContextAccessor.ContextualizeVariation(propertyType.Variations, ref culture, ref segment); foreach (var f in fallback) { switch (f) { case Fallback.None: continue; case Fallback.DefaultValue: value = defaultValue; return(true); case Fallback.Language: if (TryGetValueWithLanguageFallback(content, alias, culture, segment, out value)) { return(true); } break; default: throw NotSupportedFallbackMethod(f, "element"); } } value = default; return(false); }
/// <inheritdoc /> public bool TryGetValue(IPublishedElement content, string alias, string?culture, string?segment, Fallback fallback, object?defaultValue, out object?value) { return(TryGetValue <object>(content, alias, culture, segment, fallback, defaultValue, out value)); }
/// <inheritdoc /> public bool TryGetValue(IPublishedProperty property, string?culture, string?segment, Fallback fallback, object?defaultValue, out object?value) { return(TryGetValue <object>(property, culture, segment, fallback, defaultValue, out value)); }
/// <inheritdoc /> public virtual bool TryGetValue <T>(IPublishedContent content, string alias, string?culture, string?segment, Fallback fallback, T?defaultValue, out T?value, out IPublishedProperty?noValueProperty) { noValueProperty = default; var propertyType = content.ContentType.GetPropertyType(alias); if (propertyType != null) { _variationContextAccessor.ContextualizeVariation(propertyType.Variations, content.Id, ref culture, ref segment); noValueProperty = content.GetProperty(alias); } // note: we don't support "recurse & language" which would walk up the tree, // looking at languages at each level - should someone need it... they'll have // to implement it. foreach (var f in fallback) { switch (f) { case Fallback.None: continue; case Fallback.DefaultValue: value = defaultValue; return(true); case Fallback.Language: if (propertyType == null) { continue; } if (TryGetValueWithLanguageFallback(content, alias, culture, segment, out value)) { return(true); } break; case Fallback.Ancestors: if (TryGetValueWithAncestorsFallback(content, alias, culture, segment, out value, ref noValueProperty)) { return(true); } break; default: throw NotSupportedFallbackMethod(f, "content"); } } value = default; return(false); }
/// <inheritdoc /> public bool TryGetValue(IPublishedContent content, string alias, string?culture, string?segment, Fallback fallback, object?defaultValue, out object?value, out IPublishedProperty?noValueProperty) { return(TryGetValue <object>(content, alias, culture, segment, fallback, defaultValue, out value, out noValueProperty)); }
/// <inheritdoc /> public bool TryGetValue <T>(IPublishedProperty property, string culture, string segment, Fallback fallback, T defaultValue, out T value) { _variationContextAccessor.ContextualizeVariation(property.PropertyType.Variations, ref culture, ref segment); foreach (var f in fallback) { switch (f) { case Fallback.None: continue; case Fallback.DefaultValue: value = defaultValue; return(true); case Fallback.Language: if (TryGetValueWithLanguageFallback(property, culture, segment, out value)) { return(true); } break; default: throw NotSupportedFallbackMethod(f, "property"); } } value = default; return(false); }