private static TableDefinition<T> FromType<T>(Type type) { if (type == null) type = typeof(T); var def = new TableDefinition<T>(); var props = type .GetProperties(BindingFlags.FlattenHierarchy | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic) .Where(p => !p.IsDefined(typeof(PgSqlIgnoreAttribute))); foreach (var propertyInfo in props) { if (def.GetColumnBuilderByClrName(propertyInfo.Name) != null) continue; if (propertyInfo.GetGetMethod(true)?.IsPublic == false && !propertyInfo.IsDefined(typeof(PgSqlIncludeAttribute))) continue; ColumnBuilder col = ColumnBuilder.Build(propertyInfo.Name, propertyInfo.PropertyType); var attributes = propertyInfo.GetCustomAttributes<PgSqlAttribute>(true); foreach (var attr in attributes) { if (attr is PgSqlPrimaryKeyAttribute primaryKeyAttribute) { col.AsPrimaryKey(); if (!String.IsNullOrWhiteSpace(primaryKeyAttribute.Value?.ToString())) { col.DefaultValue(primaryKeyAttribute.Value?.ToString()); } } if (attr is PgSqlColumnAttribute colAttr) col.SetDbName(colAttr.Name); if (attr is PgSqlDefaultValueAttribute defaultvalue) col.DefaultValue(defaultvalue.Value?.ToString()); if (attr is PgSqlUniqueAttribute unique) col.MustBeUnique((bool)unique.Value); if (attr is PgSqlCustomTypeAttribute custom) col.SetCustomDbType((string)custom.Value); } def.AddColumn(col); } return def; }
public static ColumnBuilder Build(string name, Type dotnetType) { if (String.IsNullOrWhiteSpace(name)) { throw new ArgumentNullException(nameof(name)); } name = name.ClearString(); var col = new ColumnBuilder().SetClrName(name); col.Column.DotNetType = dotnetType ?? throw new ArgumentNullException(nameof(dotnetType)); return(col); }
public static ColumnBuilder Build <T>(string name) { return(ColumnBuilder.Build <T>(name)); }
public static ColumnBuilder Build(string name, string typeName) { return(ColumnBuilder.Build(name, typeName)); }
public static ColumnBuilder Build(string name, Type dotnetType) { return(ColumnBuilder.Build(name, dotnetType)); }
public ColumnBuilder AddColumn(string name, string typeName) { Column col = ColumnBuilder.Build(name, typeName); AddColumn(col); return GetColumnBuilderByClrName(col.ClrName); }