Exemplo n.º 1
0
        /// <summary>
        /// 判断是否多对一
        /// </summary>
        /// <param name="source"></param>
        /// <returns></returns>
        public static bool IsManyOne(Member source)
        {
            DataTypeInfos info = EntityFieldBase.GetTypeInfo(source);


            return(info == null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 根据类型名获取信息
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public static DataTypeInfos GetTypeInfo(string typeName)
        {
            string        key = typeName.Trim().Trim('?');
            DataTypeInfos ret = null;

            if (_dicTypeInfos.TryGetValue(key, out ret))
            {
                return(ret);
            }
            return(null);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 获取字段的配置信息
        /// </summary>
        /// <param name="fInfo"></param>
        private void GetEntityParamInfo(ClrField fInfo)
        {
            _propertyName = ToPascalName(FieldName);
            _paramName    = FieldName.Trim('_');
            DataTypeInfos info = EntityFieldBase.GetTypeInfo(fInfo);

            if (info != null)
            {
                _dbType = info.DbTypes[0].ToString();
                _length = info.DbLength;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 获取数值默认类型
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string GetMemberVariableDefaultValue(string typeName)
        {
            DataTypeInfos info = GetTypeInfo(typeName);

            if (info != null)
            {
                if (typeName.Trim().LastIndexOf('?') >= 0)
                {
                    return(info.DefaultNullValue);
                }
                return(info.DefaultValue);
            }
            return("null");
        }
Exemplo n.º 5
0
        /// <summary>
        /// 判断类型是否为非空
        /// </summary>
        /// <param name="typeName"></param>
        /// <returns></returns>
        public static bool IsNullProperty(string typeName)
        {
            DataTypeInfos info = GetTypeInfo(typeName);

            if (info != null)
            {
                if (typeName.Trim().LastIndexOf('?') >= 0)
                {
                    return(true);
                }
                else
                {
                    return(info.DefaultValue == info.DefaultNullValue);
                }
            }
            return(true);
        }
Exemplo n.º 6
0
        /// <summary>
        /// 初始化类型信息
        /// </summary>
        /// <returns></returns>
        private static Dictionary <string, DataTypeInfos> InitTypeInfos()
        {
            Dictionary <string, DataTypeInfos> dic = new Dictionary <string, DataTypeInfos>();
            DataTypeInfos info = new DataTypeInfos("Guid", new DbType[] { DbType.Guid }, "DefaultValue.DefaultGuidValue", "null", 0);

            dic["Guid"] = info;

            info = new DataTypeInfos("float", new DbType[] { DbType.Single, DbType.Currency, DbType.Decimal, DbType.Double },
                                     "DefaultValue.DefaultFloat", "DefaultValue.DefaultFloatValue", 0);
            dic["float"] = info;
            //info = new DataTypeInfos("Single", new DbType[] { DbType.Single, DbType.Currency, DbType.Decimal }, "DefaultValue.DefaultFloatValue", false);
            dic["Single"] = info;

            info = new DataTypeInfos("bool", new DbType[] {
                DbType.Boolean, DbType.Int16, DbType.Int32,
                DbType.Int64, DbType.SByte, DbType.UInt16,
                DbType.UInt32, DbType.UInt64
            },
                                     "false", "DefaultValue.DefaultBooleanValue", 0);
            dic["bool"] = info;
            //info = new DataTypeInfos("Boolean", "Boolean", "DefaultValue.DefaultBooleanValue", false);
            dic["Boolean"] = info;

            info = new DataTypeInfos("DateTime", new DbType[] { DbType.DateTime, DbType.DateTime2, DbType.DateTimeOffset, DbType.Date, DbType.Time },
                                     "DefaultValue.DefaultDateTimeValue", "null", 0);
            dic["DateTime"] = info;

            info = new DataTypeInfos("decimal", new DbType[] { DbType.Decimal, DbType.Single, DbType.Currency, DbType.Double },
                                     "DefaultValue.DefaultDecimal", "DefaultValue.DefaultDecimalValue", 0);
            dic["decimal"] = info;
            dic["Decimal"] = info;

            info = new DataTypeInfos("double", new DbType[] { DbType.Double, DbType.Single, DbType.Currency, DbType.Decimal },
                                     "DefaultValue.DefaultDouble", "DefaultValue.DefaultDoubleValue", 0);
            dic["double"] = info;
            dic["Double"] = info;

            info = new DataTypeInfos("short", new DbType[] { DbType.Int16, DbType.SByte },
                                     "DefaultValue.DefaultShort", "DefaultValue.DefaultShortValue", 0);
            dic["short"] = info;
            dic["Int16"] = info;

            info = new DataTypeInfos("int", new DbType[] { DbType.Int32, DbType.Int16, DbType.SByte },
                                     "DefaultValue.DefaultInt", "DefaultValue.DefaultIntValue", 0);
            dic["int"]   = info;
            dic["Int32"] = info;

            info = new DataTypeInfos("long", new DbType[] { DbType.Int64, DbType.Int16, DbType.SByte, DbType.Int32 },
                                     "DefaultValue.DefaultLong", "DefaultValue.DefaultLongValue", 0);
            dic["long"] = info;
            //info = new DataTypeInfos("Int64", "Int64", "DefaultValue.DefaultLongValue", false);
            dic["Int64"] = info;

            info = new DataTypeInfos("ushort", new DbType[] { DbType.Int16, DbType.SByte },
                                     "ushort.MinValue", "DefaultValue.DefaultUshortValue", 0);
            dic["ushort"] = info;
            //info = new DataTypeInfos("UInt16", "UInt16", "DefaultValue.DefaultUshortValue", false);
            dic["UInt16"] = info;

            info = new DataTypeInfos("uint", new DbType[] { DbType.Int64, DbType.Int32, DbType.Int16, DbType.SByte, },
                                     "0", "DefaultValue.DefaultUintValue", 0);
            dic["uint"]   = info;
            dic["UInt32"] = info;

            info = new DataTypeInfos("ulong", new DbType[] { DbType.Int64, DbType.Int16, DbType.SByte, DbType.Int32 },
                                     "0", "DefaultValue.DefaultUlongValue", 0);
            dic["ulong"]  = info;
            dic["UInt64"] = info;

            info = new DataTypeInfos("string", new DbType[] { DbType.AnsiString, DbType.AnsiStringFixedLength, DbType.String, DbType.StringFixedLength },
                                     "null", "null", 32);
            dic["string"] = info;
            dic["String"] = info;


            info = new DataTypeInfos("byte", new DbType[] { DbType.Byte, DbType.SByte },
                                     "0", "DefaultValue.DefaultByteValue", 0);
            dic["byte"] = info;
            dic["Byte"] = info;

            info = new DataTypeInfos("sbyte", new DbType[] { DbType.Byte, DbType.SByte },
                                     "DefaultValue.DefaultSbyte", "DefaultValue.DefaultSbyteValue", 0);
            dic["sbyte"] = info;
            dic["SByte"] = info;

            info = new DataTypeInfos("byte[]", new DbType[] { DbType.Binary },
                                     "null", "null", 512);
            dic["byte[]"] = info;
            return(dic);
        }