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; }
internal PgSqlParameter SetColum(TableDefinition tableDefinition) { if (tableDefinition != null) { var col = tableDefinition.GetColumnBuilderByClrName(ColumnName); if (col != null) { Column = col; } } return(this); }