Пример #1
0
        public object GetEntityValue(string field)
        {
            #region check the two special cases Toolbar / Presentation which the EAV doesn't know

            if (field == "Toolbar")
#pragma warning disable 612
#pragma warning disable 618
            {
                return(Toolbar.ToString());
            }
#pragma warning restore 618
#pragma warning restore 612

            if (field == ViewParts.Presentation)
            {
                return(GetPresentation);
            }

            #endregion

            // check Entity is null (in cases where null-objects are asked for properties)
            if (Entity == null)
            {
                return(null);
            }

            // check if we already have it in the cache
            if (_valCache.ContainsKey(field))
            {
                return(_valCache[field]);
            }

            var result = Entity.GetBestValue(field, Dimensions, true);
            if (result is IEnumerable <IEntity> rel)
            {
                result = new DynamicEntityWithList(Entity, field, rel, Dimensions, CompatibilityLevel, Block);
            }

            _valCache.Add(field, result);
            return(result);
        }
Пример #2
0
        private object _getValue(string field, string language = null, bool lookup = true)
        {
            var defaultMode = language == null && lookup;

            #region check the two special cases Toolbar / Presentation which the EAV doesn't know
#if NETFRAMEWORK
            // ReSharper disable once ConvertIfStatementToSwitchStatement
#pragma warning disable 618
            if (field == "Toolbar")
            {
                return(Toolbar.ToString());
            }
#pragma warning restore 618
#endif
            if (field == ViewParts.Presentation)
            {
                return(Presentation);
            }

            #endregion

            // use the standard dimensions or overload
            var dimsToUse = language == null ? Dimensions : new[] { language };

            // check Entity is null (in cases where null-objects are asked for properties)
            if (Entity == null)
            {
                return(null);
            }

            // check if we already have it in the cache - but only in normal lookups
            if (defaultMode && _valCache.ContainsKey(field))
            {
                return(_valCache[field]);
            }

            var result = Entity.GetBestValue(field, dimsToUse);

            // New mechanism to not use resolve-hyperlink
            if (lookup && result is string strResult &&
                ValueConverterBase.CouldBeReference(strResult) &&
                Entity.Attributes.ContainsKey(field) &&
                Entity.Attributes[field].Type == Eav.Constants.DataTypeHyperlink)
            {
                result = _serviceProviderOrNull?.Build <IValueConverter>()?.ToValue(strResult, EntityGuid)
                         ?? result;
            }

            if (result is IEnumerable <IEntity> rel)
            {
                // Note: if it's a Dynamic Entity without block (like App.Settings) it needs the Service Provider from this object to work
                result = new DynamicEntityWithList(Entity, field, rel, dimsToUse, CompatibilityLevel, Block,
                                                   _serviceProviderOrNull);
            }

            if (defaultMode)
            {
                _valCache.Add(field, result);
            }
            return(result);
        }