Ejemplo n.º 1
0
        /// <summary>
        /// Renders the field value for this column and the given item.
        /// </summary>
        /// <param name="item">The current item.</param>
        /// <returns>The item fields value, formatted if the Format property is set.</returns>
        public string GetRenderValue(TItem item)
        {
            // If the item is null or the field is not set then nothing to output
            if (item is null)
            {
                return(string.Empty);
            }

            // Get the value using the compiled and cached function
            var value = CompiledFunc?.Invoke(item);

            if (value == null)
            {
                return(string.Empty);
            }

            // password / sensitive info?
            if (IsPassword)
            {
                return("".PadRight(value.ToString().Length, '*'));
            }

            // if enumeration value - does it have display attribute?
            var memberInfo = Field?.GetPropertyMemberInfo();

            if (memberInfo is PropertyInfo propInfo && propInfo.PropertyType.IsEnum)
            {
                value = propInfo.PropertyType.GetMember($"{value}")
                        ?.First()
                        .GetCustomAttribute <DisplayAttribute>()
                        ?.Name ?? value;
            }

            // return the string to be rendered
            return(string.IsNullOrEmpty(Format)
                                ? value.ToString()
                                : string.Format(CultureInfo.CurrentCulture, "{0:" + Format + "}", value));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Gets the column value from the given TItem.
 /// </summary>
 /// <param name="item">The TItem for the current row.</param>
 /// <returns>The columns value.</returns>
 public object?GetValue(TItem item)
 {
     return(CompiledFunc?.Invoke(item));
 }