Пример #1
0
        /// <summary>
        /// 初始化一个TableName的实例
        /// </summary>
        /// <param name="name">表名</param>
        /// <param name="aliasName">表别名</param>
        public TableNameAttribute(String name, String aliasName = "")
        {
            Check.IfNullOrZero(name);

            TableName = BadChatDetection.FilterBadChat(name);
            if (String.IsNullOrEmpty(aliasName))
            {
                AliasName = name;
            }
            else
            {
                AliasName = BadChatDetection.FilterBadChat(aliasName);
            }
        }
Пример #2
0
        /// <summary>
        /// 转换传入的数据类型
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        private Object ParseValueType(Object obj)
        {
            Check.IfNullOrZero(obj);
            var objType = obj.GetType();

            if (objType == typeof(String))
            {
                if (_filterBadContent)
                {
                    return(BadChatDetection.FilterBadChat(obj.ToString()));
                }
                return(obj.ToString());
            }

            if (objType == typeof(Boolean))
            {
                return(obj.CastTo <Boolean>() ? 1 : 0);
            }

            if (objType.IsComplexType())
            {
                if (objType.IsArray || objType.IsCollection())
                {
                    var argument = objType.GetGenericArguments();
                    var hasValue = argument.Any();
                    if (hasValue && argument[0] == typeof(String))
                    {
                        return(String.Join(",", ((IList <String>)obj).Select(s => $@"'{s}'")));
                    }
                    if (hasValue && argument[0].IsNumeric())
                    {
                        return(String.Join(",", (IList <Int32>)obj));
                    }
                    if (hasValue && argument[0] == typeof(DateTime))
                    {
                        return(String.Join(",", (IList <DateTime>)obj));
                    }
                }
                var ex = $@"无法转换的类型{objType.Name}";
            }
            return(obj);
        }