style: 调整代码写法避免可空警告
This commit is contained in:
parent
00da8d15a2
commit
e8a471efba
@ -174,8 +174,8 @@ public static class SqlSugarSetup
|
||||
// 若创建时间为空则赋值当前时间
|
||||
else if (entityInfo.PropertyName == nameof(EntityBase.CreateTime))
|
||||
{
|
||||
var createTime = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue);
|
||||
if (createTime.Equals(DateTime.Parse("0001/1/1 0:00:00")))
|
||||
var createTime = entityInfo.EntityColumnInfo.PropertyInfo.GetValue(entityInfo.EntityValue)!;
|
||||
if (createTime.Equals(DateTime.MinValue))
|
||||
entityInfo.SetValue(DateTime.Now);
|
||||
}
|
||||
// 若当前用户非空(web线程时)
|
||||
@ -394,14 +394,14 @@ public static class SqlSugarSetup
|
||||
// 初始化业务应用种子数据
|
||||
var seedDataTypes = App.EffectiveTypes.Where(u => !u.IsInterface && !u.IsAbstract && u.IsClass && u.GetInterfaces().Any(i => i.HasImplementedRawGeneric(typeof(ISqlSugarEntitySeedData<>))))
|
||||
.Where(u => u.IsDefined(typeof(AppSeedAttribute), false))
|
||||
.OrderBy(u => u.GetCustomAttributes(typeof(SeedDataAttribute), false).Length > 0 ? (u.GetCustomAttributes(typeof(SeedDataAttribute), false)[0] as SeedDataAttribute).Order : 0).ToList();
|
||||
.OrderBy(u => u.GetCustomAttributes(typeof(SeedDataAttribute), false).Length > 0 ? ((SeedDataAttribute)u.GetCustomAttributes(typeof(SeedDataAttribute), false)[0]).Order : 0).ToList();
|
||||
|
||||
foreach (var seedType in seedDataTypes)
|
||||
{
|
||||
var instance = Activator.CreateInstance(seedType);
|
||||
var hasDataMethod = seedType.GetMethod("HasData");
|
||||
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>().ToList();
|
||||
if (seedData == null) continue;
|
||||
var seedData = ((IEnumerable)hasDataMethod?.Invoke(instance, null))?.Cast<object>().ToList() ?? new List<object>();
|
||||
if (seedData.Count == 0) continue;
|
||||
|
||||
var entityType = seedType.GetInterfaces().First().GetGenericArguments().First();
|
||||
var entityInfo = db.EntityMaintenance.GetEntityInfo(entityType);
|
||||
@ -411,7 +411,7 @@ public static class SqlSugarSetup
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(EntityTenantId.TenantId)).SetValue(sd, dbConfigId);
|
||||
sd.GetType().GetProperty(nameof(EntityTenantId.TenantId))!.SetValue(sd, dbConfigId);
|
||||
}
|
||||
}
|
||||
// 若实体包含Pid字段,则设置为当前租户Id
|
||||
@ -419,7 +419,7 @@ public static class SqlSugarSetup
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(SysOrg.Pid)).SetValue(sd, dbConfigId);
|
||||
sd.GetType().GetProperty(nameof(SysOrg.Pid))!.SetValue(sd, dbConfigId);
|
||||
}
|
||||
}
|
||||
// 若实体包含Id字段,则设置为当前租户Id递增1
|
||||
@ -427,7 +427,7 @@ public static class SqlSugarSetup
|
||||
{
|
||||
foreach (var sd in seedData)
|
||||
{
|
||||
sd.GetType().GetProperty(nameof(EntityBaseId.Id)).SetValue(sd, ++dbConfigId);
|
||||
sd.GetType().GetProperty(nameof(EntityBaseId.Id))!.SetValue(sd, ++dbConfigId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user