Skip to content

Commit

Permalink
🎨 EntityBaseClassType
Browse files Browse the repository at this point in the history
  • Loading branch information
Lxy829 committed May 27, 2024
1 parent f3c7c1d commit f758ef3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ namespace BD.Common8.SourceGenerator.Repositories.Enums;

public enum EntityBaseClassType : byte
{
TenantBaseEntityV2 = 1,
OperatorBaseEntityV2,
CreationBaseEntityV2,
TenantBaseEntity = 1,
OperatorBaseEntity,
CreationBaseEntity,
Entity,
}

Expand All @@ -14,7 +14,7 @@ static readonly ImmutableDictionary<EntityBaseClassType, ImmutableArray<FixedPro
= new Dictionary<EntityBaseClassType, ImmutableArray<FixedProperty>>
{
{
EntityBaseClassType.TenantBaseEntityV2, new FixedProperty[]
EntityBaseClassType.TenantBaseEntity, new FixedProperty[]
{
FixedProperty.TenantId,
FixedProperty.SoftDeleted,
Expand All @@ -26,7 +26,7 @@ static readonly ImmutableDictionary<EntityBaseClassType, ImmutableArray<FixedPro
}.ToImmutableArray()
},
{
EntityBaseClassType.OperatorBaseEntityV2, new FixedProperty[]
EntityBaseClassType.OperatorBaseEntity, new FixedProperty[]
{
FixedProperty.UpdateTime,
FixedProperty.OperatorUserId,
Expand All @@ -36,7 +36,7 @@ static readonly ImmutableDictionary<EntityBaseClassType, ImmutableArray<FixedPro
}.ToImmutableArray()
},
{
EntityBaseClassType.CreationBaseEntityV2, new FixedProperty[]
EntityBaseClassType.CreationBaseEntity, new FixedProperty[]
{
FixedProperty.CreationTime,
FixedProperty.CreateUserId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ public sealed record class GeneratorConfig(
var attrTypeFullNamesCfg = generatorConfig.AttributeTypeFullNames;
if (attrTypeFullNamesCfg != null)
foreach (var key_ in attrTypeFullNamesCfg)
foreach (var value_ in attrTypeFullNamesCfg)
{
if (string.IsNullOrWhiteSpace(key_)) continue;
var key = key_;
if (string.IsNullOrWhiteSpace(value_)) continue;
var value = value_;
try
{
if (!key.EndsWith("Attribute"))
key = $"{key}Attribute";
var indexD = key.LastIndexOf('.');
if (!value.EndsWith("Attribute"))
value = $"{value}Attribute";
var indexD = value.LastIndexOf('.');
if (indexD == -1) continue;
var value = key.Substring(indexD, key.Length - "Attribute".Length);
var key = value.Substring(indexD, value.Length - "Attribute".Length);
if (!attrTypeFullNames.ContainsKey(key))
attrTypeFullNames.Add(key, value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public void Calculate()
public readonly byte[]? GetBaseEntityType(EntityBaseClassType baseClassType) => baseClassType switch
{
EntityBaseClassType.Entity => Encoding.UTF8.GetBytes($"Entity<{PropertyType}>"),
EntityBaseClassType.TenantBaseEntityV2 => Encoding.UTF8.GetBytes($"TenantBaseEntity<{PropertyType}>"),
EntityBaseClassType.OperatorBaseEntityV2 => Encoding.UTF8.GetBytes($"OperatorBaseEntity<{PropertyType}>"),
EntityBaseClassType.CreationBaseEntityV2 => Encoding.UTF8.GetBytes($"CreationBaseEntity<{PropertyType}>"),
EntityBaseClassType.TenantBaseEntity => Encoding.UTF8.GetBytes($"TenantBaseEntity<{PropertyType}>"),
EntityBaseClassType.OperatorBaseEntity => Encoding.UTF8.GetBytes($"OperatorBaseEntity<{PropertyType}>"),
EntityBaseClassType.CreationBaseEntity => Encoding.UTF8.GetBytes($"CreationBaseEntity<{PropertyType}>"),
_ => default,
};

Expand Down Expand Up @@ -212,8 +212,7 @@ public readonly void Write(Stream stream, ClassType classType, bool @override =
var properties = typeof(EntityDesignPropertyMetadata).GetProperties();
foreach (var pinfo in properties)
{
if (new string[]
{ "Name", "TypeName", "DefaultValue", "Attribute", "Summary", "PreprocessorDirective", "Modifier" }
if (new[] { "Name", "TypeName", "DefaultValue", "Attribute", "Summary", "PreprocessorDirective", "Modifier" }
.Any(x => pinfo.Name.Contains(x)))
continue;

Expand Down Expand Up @@ -248,7 +247,7 @@ public readonly void Write(Stream stream, ClassType classType, bool @override =

//var constantValue = Field.IsConst ? Field.ConstantValue : null;
var constantValue = Field.DefaultValue;
var propertyType = PropertyType;
var propertyType = Field.TypeName;

#region String 类型特殊处理
if (constantValue == null)
Expand All @@ -261,14 +260,14 @@ public readonly void Write(Stream stream, ClassType classType, bool @override =
// 并且数据库必填
WriteRequired(stream);
break;
case "string?": // 类型为 String 【可】为 null 的
if (writeAttributes.Contains(TypeFullNames.Required)) // 但是有数据库必填
{
// 将类型更改为不可 null,并设置默认值空字符串
propertyType = "string";
constantValue = "\"\"";
}
break;
//case "string?": // 类型为 String 【可】为 null 的
// if (writeAttributes.Contains(TypeFullNames.Required)) // 但是有数据库必填
// {
// // 将类型更改为不可 null,并设置默认值空字符串
// propertyType = "string";
// constantValue = "\"\"";
// }
// break;
}
}

Expand Down

0 comments on commit f758ef3

Please sign in to comment.