Пример #1
0
        /// <summary>
        /// 获取单元格要输出的内容
        /// </summary>
        /// <param name="source">源数据</param>
        /// <param name="needFormat">是否使用format</param>
        /// <returns>Html内容</returns>
        public virtual object GetText(object source, bool needFormat = true)
        {
            object rv  = null;
            var    col = CompiledCol?.Invoke(source as T);

            if (Format == null || (needFormat == false && Format.Method.ReturnType != typeof(string)))
            {
                if (col == null)
                {
                    rv = null;
                }
                else if (col is DateTime dateTime)
                {
                    rv = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
                }
                else if (col != null && col is DateTime?)
                {
                    rv = (col as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss");
                }
                else if (col.GetType().IsEnumOrNullableEnum())
                {
                    rv = (int)col;
                }
                else if (col.GetType().Namespace.Equals("System") == false)
                {
                    if (needFormat == false)
                    {
                        rv = JsonConvert.SerializeObject(col);
                    }
                    else
                    {
                        rv = col.ToString();
                    }
                }
                else
                {
                    rv = col.ToString();
                }
            }
            else
            {
                rv = Format.Invoke(source as T, col);
            }
            if (rv == null)
            {
                rv = "";
            }
            return(rv);
        }
Пример #2
0
        /// <summary>
        /// 获取单元格要输出的内容
        /// </summary>
        /// <param name="source">源数据</param>
        /// <param name="needFormat">是否使用format</param>
        /// <returns>Html内容</returns>
        public virtual object GetText(object source, bool needFormat = true)
        {
            object rv  = null;
            var    col = CompiledCol?.Invoke(source as T);

            if (Format == null || (needFormat == false && Format.Method.ReturnType != typeof(string)))
            {
                rv = col?.ToString();
            }
            else
            {
                rv = Format.Invoke(source as T, col);
            }
            if (rv == null)
            {
                rv = "";
            }
            return(rv);
        }
Пример #3
0
        /// <summary>
        /// 获取单元格要输出的内容
        /// </summary>
        /// <param name="source">源数据</param>
        /// <returns>Html内容</returns>
        public virtual object GetText(object source)
        {
            object rv  = null;
            var    col = CompiledCol?.Invoke(source as T);

            if (Format == null)
            {
                rv = col?.ToString();
            }
            else
            {
                rv = Format.Invoke(source as T, col);
            }
            if (rv == null)
            {
                rv = "";
            }
            return(rv);
        }
Пример #4
0
        /// <summary>
        /// 获取单元格要输出的内容
        /// </summary>
        /// <param name="source">源数据</param>
        /// <param name="needFormat">是否使用format</param>
        /// <returns>Html内容</returns>
        public virtual object GetText(object source, bool needFormat = true)
        {
            object rv  = null;
            var    col = CompiledCol?.Invoke(source as T);

            if (Format == null || (needFormat == false && Format.Method.ReturnType != typeof(string)))
            {
                if (col == null)
                {
                    rv = null;
                }
                else if (col is DateTime dateTime)
                {
                    rv = dateTime.ToString("yyyy-MM-dd HH:mm:ss");
                }
                else if (col != null && col is DateTime?)
                {
                    rv = (col as DateTime?).Value.ToString("yyyy-MM-dd HH:mm:ss");
                }
                else if (col is Enum)
                {
                    rv = (int)col;
                }
                else
                {
                    rv = col?.ToString();
                }
            }
            else
            {
                rv = Format.Invoke(source as T, col);
            }
            if (rv == null)
            {
                rv = "";
            }
            return(rv);
        }
Пример #5
0
 public virtual object GetObject(object source)
 {
     object rv = CompiledCol?.Invoke(source as T);
     return rv;
 }