Exemple #1
0
        /// <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);

            var includeFallbackLanguage = fallback.Contains(Fallback.DisplayFallbackLanguage);

            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, includeFallbackLanguage))
                    {
                        return(true);
                    }
                    break;

                case Fallback.DisplayFallbackLanguage:
                    continue;

                default:
                    throw NotSupportedFallbackMethod(f, "property");
                }
            }

            value = default;
            return(false);
        }
Exemple #2
0
        /// <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 includeFallbackLanguage = fallback.Contains(Fallback.DisplayFallbackLanguage);

            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, includeFallbackLanguage))
                    {
                        return(true);
                    }
                    break;

                case Fallback.Ancestors:
                    if (TryGetValueWithAncestorsFallback(content, alias, culture, segment, out value, ref noValueProperty, includeFallbackLanguage))
                    {
                        return(true);
                    }
                    break;

                case Fallback.DisplayFallbackLanguage:
                    continue;

                default:
                    throw NotSupportedFallbackMethod(f, "content");
                }
            }

            value = default;
            return(false);
        }