public ColumnDescriptor(PropertyInfo property, ISqlAdapter sqlAdapter) { if (property == null) { return; } var columnAttribute = property.GetCustomAttribute <ColumnAttribute>(); if (columnAttribute != null) { Name = columnAttribute.Name; TypeName = columnAttribute.TypeName; DefaultValue = columnAttribute.DefaultValue; } if (Name.IsNull()) { Name = property.Name; } PropertyInfo = property; IsPrimaryKey = Attribute.GetCustomAttributes(property).Any(attr => attr.GetType() == typeof(KeyAttribute)); if (!IsPrimaryKey) { IsPrimaryKey = property.Name.Equals("Id", StringComparison.OrdinalIgnoreCase); } var lengthAtt = property.GetCustomAttribute <LengthAttribute>(); if (lengthAtt != null) { Length = lengthAtt.Length < 1 ? 50 : lengthAtt.Length; } var maxAtt = property.GetCustomAttribute <MaxAttribute>(); Max = maxAtt != null; if (property.PropertyType.IsNullable()) { Nullable = true; } else { var nullableAtt = property.GetCustomAttribute <NullableAttribute>(); Nullable = nullableAtt != null; } var precisionAtt = property.GetCustomAttribute <PrecisionAttribute>(); if (precisionAtt != null) { PrecisionM = precisionAtt.M; PrecisionD = precisionAtt.D; } //解析列类型名称和默认值 var typeName = sqlAdapter.GetColumnTypeName(this, out string defaultValue); if (TypeName.IsNull()) { TypeName = typeName; } if (DefaultValue.IsNull()) { DefaultValue = defaultValue; } }