Пример #1
0
        /// <summary>
        /// Get Property out of NameValueCollection
        /// </summary>
        /// <param name="strPropertyName"></param>
        /// <param name="strFormat"></param>
        /// <returns></returns>
        private string GetProperty(string strPropertyName, string strFormat)
        {
            // Return empty string if Entity is null
            if (_entity == null)
            {
                return(string.Empty);
            }

            var outputFormat = strFormat == string.Empty ? "g" : strFormat;

            // If it's a repeater token for list index or something, get that first (or null)
            // Otherwise just get the normal value
            var valueObject = ResolveRepeaterTokens(strPropertyName)
                              ?? _entity.Get(strPropertyName);

            if (valueObject != null)
            {
                switch (Type.GetTypeCode(valueObject.GetType()))
                {
                case TypeCode.String:
                    return(LookUpBase.FormatString((string)valueObject, strFormat));

                case TypeCode.Boolean:
                    // #BreakingChange v11.11 - possible breaking change
                    // previously it converted true/false to language specific values
                    // but only in token templates (and previously also app-settings) which causes
                    // the use to have to be language aware - very complex
                    // I'm pretty sure this won't affect anybody
                    // old: ((bool)valueObject).ToString(formatProvider).ToLowerInvariant();
                    return(LookUpBase.Format((bool)valueObject));

                case TypeCode.DateTime:
                case TypeCode.Double:
                case TypeCode.Single:
                case TypeCode.Int16:
                case TypeCode.Int32:
                case TypeCode.Int64:
                case TypeCode.Decimal:
                    return(((IFormattable)valueObject).ToString(outputFormat, GetCultureInfo()));

                default:
                    return(LookUpBase.FormatString(valueObject.ToString(), strFormat));
                }
            }

            #region Check for Navigation-Property (e.g. Manager:Name)

            if (!strPropertyName.Contains(':'))
            {
                return(string.Empty);
            }

            var propertyMatch = Regex.Match(strPropertyName, "([a-z]+):([a-z]+)", RegexOptions.IgnoreCase);
            if (!propertyMatch.Success)
            {
                return(string.Empty);
            }

            valueObject = _entity.Get(propertyMatch.Groups[1].Value);
            if (valueObject == null)
            {
                return(string.Empty);
            }

            #region Handle Entity-Field (List of DynamicEntity)
            var list = valueObject as List <IDynamicEntity>;

            var entity = list?.FirstOrDefault() ?? valueObject as IDynamicEntity;

            if (entity != null)
            {
                return(new LookUpForTokenTemplate(null, entity).GetProperty(propertyMatch.Groups[2].Value, string.Empty));
            }

            #endregion

            return(string.Empty);

            #endregion
        }
Пример #2
0
        /// <summary>
        /// Get Property out of NameValueCollection
        /// </summary>
        /// <param name="strPropertyName"></param>
        /// <param name="strFormat"></param>
        /// <param name="formatProvider"></param>
        /// <param name="propertyNotFound"></param>
        /// <returns></returns>
        public string GetProperty(string strPropertyName, string strFormat, CultureInfo formatProvider, ref bool propertyNotFound)
        {
            // Return empty string if Entity is null
            if (_entity == null)
            {
                return(string.Empty);
            }

            var outputFormat = strFormat == string.Empty ? "g" : strFormat;

            var propNotFound = false;

            string repeaterHelper = null;

            if (_repeaterIndex > -1 && strPropertyName.StartsWith(TokenRepeater + ":", StringComparison.OrdinalIgnoreCase))
            {
                switch (strPropertyName.Substring(TokenRepeater.Length + 1).ToLower())
                {
                case KeyIndex:
                    repeaterHelper = (_repeaterIndex).ToString();
                    break;

                case KeyIndex1:
                    repeaterHelper = (_repeaterIndex + 1).ToString();
                    break;

                case KeyAlternator2:
                    repeaterHelper = (_repeaterIndex % 2).ToString();
                    break;

                case KeyAlternator3:
                    repeaterHelper = (_repeaterIndex % 3).ToString();
                    break;

                case KeyAlternator4:
                    repeaterHelper = (_repeaterIndex % 4).ToString();
                    break;

                case KeyAlternator5:
                    repeaterHelper = (_repeaterIndex % 5).ToString();
                    break;

                case KeyIsFirst:
                    repeaterHelper = (_repeaterIndex == 0) ? "First" : "";
                    break;

                case KeyIsLast:
                    repeaterHelper = (_repeaterIndex == _repeaterTotal - 1) ? "Last" : "";
                    break;

                case KeyCount:
                    repeaterHelper = _repeaterTotal.ToString();
                    break;
                }
            }

            var valueObject = repeaterHelper ?? _entity.Get(strPropertyName);

            if (valueObject != null)
            {
                switch (valueObject.GetType().Name)
                {
                case "String":
                    return(LookUpBase.FormatString((string)valueObject, strFormat));

                case "Boolean":
                    return(((bool)valueObject).ToString(formatProvider).ToLower());

                case "DateTime":
                case "Double":
                case "Single":
                case "Int32":
                case "Int64":
                case "Decimal":
                    return(((IFormattable)valueObject).ToString(outputFormat, formatProvider));

                default:
                    return(LookUpBase.FormatString(valueObject.ToString(), strFormat));
                }
            }

            #region Check for Navigation-Property (e.g. Manager:Name)
            if (strPropertyName.Contains(':'))
            {
                var propertyMatch = Regex.Match(strPropertyName, "([a-z]+):([a-z]+)", RegexOptions.IgnoreCase);
                if (propertyMatch.Success)
                {
                    valueObject = _entity.Get(propertyMatch.Groups[1].Value);
                    if (valueObject != null)
                    {
                        #region Handle Entity-Field (List of DynamicEntity)
                        var list = valueObject as List <IDynamicEntity>;

                        var entity = list != null?list.FirstOrDefault() : null;

                        if (entity == null)
                        {
                            entity = valueObject as IDynamicEntity;
                        }

                        if (entity != null)
                        {
                            return(new LookUpInDynamicEntity(null, entity).GetProperty(propertyMatch.Groups[2].Value, string.Empty, formatProvider, /*AccessingUser,*/ /*AccessLevel,*/ ref propNotFound));
                        }

                        #endregion

                        return(string.Empty);
                    }
                }
            }
            #endregion

            propertyNotFound = true;
            return(string.Empty);
        }