提交代码

This commit is contained in:
zpc 2024-11-02 02:03:25 +08:00
parent 9ca49db15c
commit f221d18cd9
20 changed files with 424 additions and 835 deletions

View File

@ -63,6 +63,17 @@ namespace CloudGaming.Code.Cache
/// 菜单分类 /// 菜单分类
/// </summary> /// </summary>
public List<T_Epg_CategoryCfg> EpgCategoryCfg => GetCacheList(ref _epgCategoryCfg, it => it.IsOnline); public List<T_Epg_CategoryCfg> EpgCategoryCfg => GetCacheList(ref _epgCategoryCfg, it => it.IsOnline);
#endregion
#region
//private CommonDataEntityCache<T_Game_List>? _gameList;
///// <summary>
///// 菜单分类
///// </summary>
//public List<T_Game_List> GameList => GetCacheList(ref _gameList);
#endregion #endregion
} }

View File

@ -1,3 +1,4 @@
using CloudGaming.Code.Cache;
using CloudGaming.DtoModel.Epg; using CloudGaming.DtoModel.Epg;
using System; using System;
@ -24,7 +25,7 @@ namespace CloudGaming.Code.Epg
/// <returns></returns> /// <returns></returns>
public async Task<List<EpgCategoryDto>> GetHomeInfo() public async Task<List<EpgCategoryDto>> GetHomeInfo()
{ {
var listQueryable = GetEpgCategory("Home").AsQueryable(); var listQueryable = GetEpgCategory(EpgEnum.EpgCatIdName.).AsQueryable();
if (IsChecking) if (IsChecking)
{ {
listQueryable = listQueryable.Where(it => it.ShowStatus == 0 || it.ShowStatus == 2).AsQueryable(); listQueryable = listQueryable.Where(it => it.ShowStatus == 0 || it.ShowStatus == 2).AsQueryable();
@ -38,22 +39,46 @@ namespace CloudGaming.Code.Epg
List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>(); List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
list.ForEach(it => list.ForEach(it =>
{ {
EpgCategoryDto epgCategoryDto = new EpgCategoryDto() var list = new List<EpgInfo>()
{ {
CategoryName = it.Name,
CategoryType = it.IdName,
IsQuickStartPopUp = it.IsQuickStartPopUp ?? false,
ShowNum_Index = it.ShowNumIndex ?? 0,
EpgList = new List<EpgInfo>()
{
},
}; };
if (it.Id == list[0].Id) if (it.IdName == EpgEnum.EpgCatIdName.banner滚动栏)
{ {
epgCategoryDto.EpgList.Add(new EpgInfo() { CornerIcon = 1, IdName = "111" }); var epgList = GetEpgList(it.Id);
epgList.ForEach(item =>
{
if (item.ResType == (int)EpgEnum.EpgResType.)
{
}
EpgInfo epgInfo = new EpgInfo()
{
CornerIcon = item.CornerIconId,
EpgId = item.EpgId,
Pic = item.ImageId,
//GameIconImage = item.
};
});
}
if (list.Count > 0)
{
EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
{
CategoryName = it.Name,
CategoryType = it.IdName,
IsQuickStartPopUp = it.IsQuickStartPopUp ?? false,
ShowNum_Index = it.ShowNumIndex ?? 0,
EpgList = list
};
epgCategoryDtos.Add(epgCategoryDto);
} }
epgCategoryDtos.Add(epgCategoryDto);
}); });
return epgCategoryDtos; return epgCategoryDtos;
} }
@ -71,5 +96,22 @@ namespace CloudGaming.Code.Epg
} }
return new List<T_Epg_CategoryCfg>(); return new List<T_Epg_CategoryCfg>();
} }
/// <summary>
///
/// </summary>
/// <param name="idName"></param>
/// <returns></returns>
public List<T_Epg_Cfg> GetEpgList(int epgParentCategoryId)
{
var list = CloudGamingCacheExtend.GetDataEntityCache<T_Epg_Cfg>(this, it => it.IsOnline);
DateTime currentHour = DateTime.Now.Date.AddHours(DateTime.Now.Hour);
if (list?.DataList?.Count > 0)
{
var dataList = list.DataList.Where(it => it.EpgCategory == epgParentCategoryId && it.StartEnableTime < currentHour && it.EndEnableTime > currentHour).ToList();
return dataList;
}
return null;
}
} }
} }

View File

@ -25,7 +25,7 @@ namespace CloudGaming.Test
} }
//[Benchmark] [Benchmark]
public object ObjectToDictionaryOrListTest1() public object ObjectToDictionaryOrListTest1()
{ {
EpgCategoryDto epgCategoryDto = new EpgCategoryDto() EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
@ -52,7 +52,7 @@ namespace CloudGaming.Test
} }
//[Benchmark] [Benchmark]
public object ListToDictionaryOrListTest1() public object ListToDictionaryOrListTest1()
{ {
@ -221,7 +221,7 @@ namespace CloudGaming.Test
} }
[Benchmark] // [Benchmark]
public object ObjectToDictionaryOrListExtend4() public object ObjectToDictionaryOrListExtend4()
{ {
EpgCategoryDto epgCategoryDto = new EpgCategoryDto() EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
@ -247,7 +247,7 @@ namespace CloudGaming.Test
} }
[Benchmark] //[Benchmark]
public object ListToDictionaryOrListExtend4() public object ListToDictionaryOrListExtend4()
{ {
List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>(); List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
@ -285,7 +285,7 @@ namespace CloudGaming.Test
} }
[Benchmark] //[Benchmark]
public object ObjectToDictionaryOrListExtend6() public object ObjectToDictionaryOrListExtend6()
{ {
EpgCategoryDto epgCategoryDto = new EpgCategoryDto() EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
@ -310,8 +310,8 @@ namespace CloudGaming.Test
} }
//
[Benchmark] //[Benchmark]
public object ListToDictionaryOrListExtend6() public object ListToDictionaryOrListExtend6()
{ {
List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>(); List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
@ -349,7 +349,7 @@ namespace CloudGaming.Test
} }
[Benchmark] //[Benchmark]
public object ObjectToDictionaryOrListExtend7() public object ObjectToDictionaryOrListExtend7()
{ {
EpgCategoryDto epgCategoryDto = new EpgCategoryDto() EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
@ -375,7 +375,7 @@ namespace CloudGaming.Test
} }
[Benchmark] //[Benchmark]
public object ListToDictionaryOrListExtend7() public object ListToDictionaryOrListExtend7()
{ {
List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>(); List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();
@ -412,7 +412,7 @@ namespace CloudGaming.Test
return dic; return dic;
} }
[Benchmark] //[Benchmark]
public object ObjectToDictionaryOrListExtend8() public object ObjectToDictionaryOrListExtend8()
{ {
EpgCategoryDto epgCategoryDto = new EpgCategoryDto() EpgCategoryDto epgCategoryDto = new EpgCategoryDto()
@ -438,7 +438,7 @@ namespace CloudGaming.Test
} }
[Benchmark] // [Benchmark]
public object ListToDictionaryOrListExtend8() public object ListToDictionaryOrListExtend8()
{ {
List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>(); List<EpgCategoryDto> epgCategoryDtos = new List<EpgCategoryDto>();

View File

@ -0,0 +1,143 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CloudGaming.DtoModel.Epg
{
/// <summary>
/// Epg配置相关枚举
/// </summary>
public class EpgEnum
{
/// <summary>
/// 常用epg分组-标识IdName
/// </summary>
public static class EpgCatIdName
{
public const string = "Home";
public const string = "HotIndex";
public const string = "HotTagIndex";
public const string banner滚动栏 = "Banner";
public const string = "HallFour";
public const string = "RandIndex";
public const string = "NewIndex";
public const string = "FightGame";
public const string = "GameLive";
public const string = "VideoLive";
public const string = "MyHistory";
}
/// <summary>
/// 资源图片样式,尺寸
/// </summary>
public enum ImageResStyle
{
/// <summary>
/// 游戏-尊享推荐, 竖版 Image_Shu
/// </summary>
Game尊享推荐_312_420 = 1,
/// <summary>
/// 游戏-推荐位大图 Image_Block2
/// </summary>
Game推荐位大图_984_520 = 2,
/// <summary>
/// 游戏-精选推荐, 豆腐块图 Image_Block
/// </summary>
Game精选推荐_474_300 = 3,
/// <summary>
/// 游戏-最近推出, 竖版2高一点的最近推出 Image_Shu2
/// </summary>
Game最近推出_360_548 = 4,
/// <summary>
/// 游戏-游戏库, 正方形 (GameImageId)
/// </summary>
Game游戏库_180_180 = 5,
}
/// <summary>
/// 资源类型
/// </summary>
public enum EpgResType
{
/// <summary>
/// 没有特殊说明作用,一般用来标记下
/// </summary>
= 0,
/// <summary>
/// 对应游戏Id
/// </summary>
= 4,
= 7,
= 8,
/// <summary>
/// 对应H5地址
/// </summary>
H5页面 = 9,
/// <summary>
/// 对应浏览器地址IOS专用
/// </summary>
= 10,
/// <summary>
/// 对应游戏id, 跳到游戏房间界面,为空则进联机大厅
/// </summary>
= 11,
/// <summary>
/// 对应H5地址——原生地址
/// </summary>
H5页面_原生 = 12,
/// <summary>
/// 对应栏目标识如SubjectIndexTaskActivityHistory等
/// </summary>
= 21,
/// <summary>
/// 对应弹窗Id显示对应的弹窗
/// </summary>
= 101,
}
/// <summary>
/// 客户端的跳转类型
/// 示例holybladeData={"dataType":9"dataId":"https://moguext.moguyouxi.cn/moguext/ui/bbs/autologin"}
/// </summary>
public enum JumpDataType
{
/// <summary>
/// dataId=咨询Id
/// </summary>
= 1,
= 2,
= 3,
= 4,
= 5,
/// <summary>
/// 应该不用了
/// </summary>
= 6,
/// <summary>
/// dataId无
/// </summary>
= 7,
/// <summary>
/// dataId无
/// </summary>
= 8,
/// <summary>
/// dataId=h5页面完整地址
/// </summary>
h5页面 = 9,
}
}
}

View File

@ -45,65 +45,15 @@ public partial class CloudGamingGameContext : DbContext
/// <summary> /// <summary>
/// 难度列表 /// 游戏多选保存
/// </summary>
public virtual DbSet<T_CGame_Difficultys> T_CGame_Difficultys { get; set; }
/// <summary>
/// 游戏中配置
/// </summary>
public virtual DbSet<T_GameConfig> T_GameConfig { get; set; }
/// <summary>
/// 游戏多选保存1 游戏类型 2 游戏标签 3 游戏心得4 游戏介绍 5 游戏操作心得
/// </summary> /// </summary>
public virtual DbSet<T_Game_ChildList> T_Game_ChildList { get; set; } public virtual DbSet<T_Game_ChildList> T_Game_ChildList { get; set; }
/// <summary>
/// 游戏多选保存1 游戏类型2 游戏标签3 游戏心得 4 游戏介绍5 游戏操作心得
/// </summary>
public virtual DbSet<T_Game_ChildTypes> T_Game_ChildTypes { get; set; }
/// <summary>
/// 游戏桌面配置
/// </summary>
public virtual DbSet<T_Game_DesktopConfig> T_Game_DesktopConfig { get; set; }
/// <summary>
/// 游戏开发商公司
/// </summary>
public virtual DbSet<T_Game_DeveloperCompanys> T_Game_DeveloperCompanys { get; set; }
/// <summary>
/// 开发商
/// </summary>
public virtual DbSet<T_Game_Developers> T_Game_Developers { get; set; }
/// <summary>
/// 发行方信息
/// </summary>
public virtual DbSet<T_Game_Issuers> T_Game_Issuers { get; set; }
/// <summary> /// <summary>
/// 游戏列表 /// 游戏列表
/// </summary> /// </summary>
public virtual DbSet<T_Game_List> T_Game_List { get; set; } public virtual DbSet<T_Game_List> T_Game_List { get; set; }
/// <summary>
/// 游戏操作类型
/// </summary>
public virtual DbSet<T_Game_OperationModes> T_Game_OperationModes { get; set; }
/// <summary>
/// 预加载游戏
/// </summary>
public virtual DbSet<T_Game_Preload> T_Game_Preload { get; set; }
/// <summary>
/// 游戏设置配置
/// </summary>
public virtual DbSet<T_Game_Setting> T_Game_Setting { get; set; }
/// <summary> /// <summary>
/// 游戏标签 /// 游戏标签
/// </summary> /// </summary>
@ -124,220 +74,46 @@ public partial class CloudGamingGameContext : DbContext
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
modelBuilder.Entity<T_CGame_Difficultys>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK_T_CGAME_DIFFICULTYS");
entity.ToTable(tb => tb.HasComment("难度列表"));
entity.Property(e => e.CreatTime).HasColumnType("datetime");
entity.Property(e => e.Desc)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.DiffcultyName)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
});
modelBuilder.Entity<T_GameConfig>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK_T_UI_GAMECONFIG");
entity.ToTable(tb => tb.HasComment("游戏中配置"));
entity.Property(e => e.BuyPopId)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.Desc)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
entity.Property(e => e.VipBuyPopId)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
});
modelBuilder.Entity<T_Game_ChildList>(entity => modelBuilder.Entity<T_Game_ChildList>(entity =>
{ {
entity.HasKey(e => e.Id).HasName("PK_T_CGAME_CHILDLIST"); entity.HasKey(e => e.Id).HasName("PK_T_CGAME_CHILDLIST");
entity.ToTable(tb => tb.HasComment("游戏多选保存1 游戏类型 2 游戏标签 3 游戏心得4 游戏介绍 5 游戏操作心得")); entity.ToTable(tb => tb.HasComment("游戏多选保存"));
entity.Property(e => e.ChildId).HasComment("配置表Id");
entity.Property(e => e.ChildType).HasComment("1 游戏类型 2 游戏标签");
entity.Property(e => e.Desc) entity.Property(e => e.Desc)
.HasMaxLength(100) .HasMaxLength(100)
.HasComment("描述")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.GameId) entity.Property(e => e.GameId)
.HasMaxLength(100) .HasMaxLength(100)
.HasComment("游戏Id")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.OrderId).HasComment("排序Id"); entity.Property(e => e.OrderId).HasComment("排序Id");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
});
modelBuilder.Entity<T_Game_ChildTypes>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK_T_CGAME_CHILDTYPES");
entity.ToTable(tb => tb.HasComment("游戏多选保存1 游戏类型2 游戏标签3 游戏心得 4 游戏介绍5 游戏操作心得"));
entity.Property(e => e.ChildIdName)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.Desc)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
});
modelBuilder.Entity<T_Game_DesktopConfig>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK_T_CGAME_DESKTOPCONFIG");
entity.ToTable(tb => tb.HasComment("游戏桌面配置"));
entity.Property(e => e.Id).HasComment("主键,唯一标识");
entity.Property(e => e.BackGroundImage).HasComment("背景图片");
entity.Property(e => e.CreateTime)
.HasComment("创建时间")
.HasColumnType("datetime");
entity.Property(e => e.CreateUserName)
.HasMaxLength(100)
.HasComment("创建人")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.GameId)
.HasMaxLength(100)
.HasComment("游戏ID")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.GameName)
.HasMaxLength(100)
.HasComment("游戏名称")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.RestartImage).HasComment("重新启动图片");
entity.Property(e => e.RestartImageStyleLeft)
.HasMaxLength(20)
.HasComment("重新启动图片Left")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.RestartImageStyleTop)
.HasMaxLength(20)
.HasComment("重新启动图片Top")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.StartArgs)
.HasMaxLength(100)
.HasComment("启动参数")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.StartPath)
.HasMaxLength(200)
.HasComment("启动路径")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.SteamImage).HasComment("Steam图片");
entity.Property(e => e.SteamImageStyleLeft)
.HasMaxLength(20)
.HasComment("Steam图片样式")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.SteamImageStyleTop)
.HasMaxLength(20)
.HasComment("Steam图片样式")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.StopImage).HasComment("断开连接图片");
entity.Property(e => e.StopImageStyleLeft)
.HasMaxLength(100)
.HasComment("断开连接图片Left")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.StopImageStyleTop)
.HasMaxLength(100)
.HasComment("断开连接图片Top")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime)
.HasComment("修改时间")
.HasColumnType("datetime");
entity.Property(e => e.UpdateUserName)
.HasMaxLength(100)
.HasComment("创建时间")
.UseCollation("Chinese_PRC_CI_AS");
});
modelBuilder.Entity<T_Game_DeveloperCompanys>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK_T_CGAME_DEVELOPERCOMPANYS");
entity.ToTable(tb => tb.HasComment("游戏开发商公司"));
entity.Property(e => e.CompanyName)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.CreatTime).HasColumnType("datetime");
entity.Property(e => e.Desc)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
});
modelBuilder.Entity<T_Game_Developers>(entity =>
{
entity.HasKey(e => e.ID).HasName("PK_T_CGAME_DEVELOPERS");
entity.ToTable(tb => tb.HasComment("开发商"));
entity.Property(e => e.CreatTime).HasColumnType("datetime");
entity.Property(e => e.Desc)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.DeveloperName)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
});
modelBuilder.Entity<T_Game_Issuers>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK_T_CGAME_ISSUERS");
entity.ToTable(tb => tb.HasComment("发行方信息"));
entity.Property(e => e.CreatTime).HasColumnType("datetime");
entity.Property(e => e.Desc)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.IssuerName)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
}); });
modelBuilder.Entity<T_Game_List>(entity => modelBuilder.Entity<T_Game_List>(entity =>
{ {
entity.HasKey(e => e.ID).HasName("PK_T_CGAME_LIST"); entity.HasKey(e => e.Id).HasName("PK_T_CGAME_LIST");
entity.ToTable(tb => tb.HasComment("游戏列表")); entity.ToTable(tb => tb.HasComment("游戏列表"));
entity.Property(e => e.CPCompany) entity.Property(e => e.DCompany)
.HasMaxLength(50) .HasMaxLength(50)
.HasDefaultValue("") .HasComment("云开发公司");
.HasComment("配对合作方公司")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.CPId)
.HasMaxLength(50)
.HasDefaultValue("")
.HasComment("配对id用来放置合作游戏方游戏id如方块科技之类的")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.CPIsFree).HasComment("配对第三方游戏是否免费0:免费,1收费");
entity.Property(e => e.DCompanyId).HasComment("CP开发公司");
entity.Property(e => e.Desc) entity.Property(e => e.Desc)
.HasMaxLength(100) .HasMaxLength(100)
.HasComment("备注")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.DeveloperId).HasComment("游戏开发方");
entity.Property(e => e.GameCloudId) entity.Property(e => e.GameCloudId)
.HasMaxLength(50) .HasMaxLength(50)
.HasComment("CP游戏Id") .HasComment("云游戏Id")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.GameDifficulty)
.HasMaxLength(10)
.HasComment("游戏难度");
entity.Property(e => e.GameId) entity.Property(e => e.GameId)
.HasMaxLength(100) .HasMaxLength(100)
.HasComment("我们自己的游戏Id") .HasComment("我们自己的游戏Id")
@ -347,105 +123,36 @@ public partial class CloudGamingGameContext : DbContext
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.GameIsAdapter).HasComment("游戏是否适配"); entity.Property(e => e.GameIsAdapter).HasComment("游戏是否适配");
entity.Property(e => e.GameIsCrack).HasComment("游戏是否破解"); entity.Property(e => e.GameIsCrack).HasComment("游戏是否破解");
entity.Property(e => e.GameIsDevelopers).HasComment("游戏是否开发");
entity.Property(e => e.GameIsEditionMouse).HasComment("是否隐藏鼠标"); entity.Property(e => e.GameIsEditionMouse).HasComment("是否隐藏鼠标");
entity.Property(e => e.GameIsEditionNumber) entity.Property(e => e.GameIsEditionNumber).HasComment("是否有版号");
.HasDefaultValue(false) entity.Property(e => e.GameIsSaveFile).HasComment("是否存档");
.HasComment("是否有版号");
entity.Property(e => e.GameIsVersion).HasComment("游戏是否有版权"); entity.Property(e => e.GameIsVersion).HasComment("游戏是否有版权");
entity.Property(e => e.GameIssuerId) entity.Property(e => e.GameIssuer)
.HasMaxLength(100) .HasMaxLength(100)
.HasComment("游戏发行方") .HasComment("游戏发行方")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.GameName) entity.Property(e => e.GameName)
.HasMaxLength(100) .HasMaxLength(100)
.HasComment("游戏名称")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.GameRecommend) entity.Property(e => e.GameOperationModel)
.HasMaxLength(1000) .HasMaxLength(255)
.HasComment("游戏推荐") .HasComment("游戏操作类型");
.UseCollation("Chinese_PRC_CI_AS"); entity.Property(e => e.GamePeopleNum)
entity.Property(e => e.GameSize) .HasDefaultValue(1)
.HasMaxLength(100) .HasComment("游戏人数");
.UseCollation("Chinese_PRC_CI_AS"); entity.Property(e => e.OrderId).HasComment("游戏排序");
entity.Property(e => e.GameVersionDesc)
.HasMaxLength(100)
.HasComment("游戏版本详情")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.GameVersionNum)
.HasMaxLength(100)
.HasComment("游戏版本号")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.ScreenOrientation).HasComment("屏幕方向0-横屏 1-竖屏"); entity.Property(e => e.ScreenOrientation).HasComment("屏幕方向0-横屏 1-竖屏");
entity.Property(e => e.ServerPattern)
.HasDefaultValue(0)
.HasComment("服务器模式0容器1云桌面3海马云");
entity.Property(e => e.SteamId) entity.Property(e => e.SteamId)
.HasMaxLength(30) .HasMaxLength(30)
.HasComment("steam")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
});
modelBuilder.Entity<T_Game_OperationModes>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK_T_CGAME_OPERATIONMODES");
entity.ToTable(tb => tb.HasComment(" 游戏操作类型"));
entity.Property(e => e.CreatTime).HasColumnType("datetime");
entity.Property(e => e.Desc)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.Name)
.HasMaxLength(50)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
});
modelBuilder.Entity<T_Game_Preload>(entity =>
{
entity.ToTable(tb => tb.HasComment("预加载游戏"));
entity.Property(e => e.Id).HasComment("自增");
entity.Property(e => e.CreateTime)
.HasDefaultValueSql("(getdate())")
.HasComment("创建时间")
.HasColumnType("datetime");
entity.Property(e => e.GameId)
.HasMaxLength(50)
.HasDefaultValue("")
.HasComment("游戏Id")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.PreloadSum).HasComment("预加载数量");
entity.Property(e => e.UpdateTime) entity.Property(e => e.UpdateTime)
.HasDefaultValueSql("(getdate())")
.HasComment("修改时间") .HasComment("修改时间")
.HasColumnType("datetime"); .HasColumnType("datetime");
}); });
modelBuilder.Entity<T_Game_Setting>(entity =>
{
entity.HasKey(e => e.Id).HasName("PK_T_GAME_SETTING");
entity.ToTable(tb => tb.HasComment("游戏设置配置"));
entity.Property(e => e.CreateTime).HasColumnType("datetime");
entity.Property(e => e.Desc)
.HasMaxLength(100)
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.IsOnline).HasComment("是否显示");
entity.Property(e => e.Name)
.HasMaxLength(100)
.HasComment("设置名字")
.UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.OrderId).HasComment("设置排序");
entity.Property(e => e.SettingId).HasComment("设置Id");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
});
modelBuilder.Entity<T_Game_Tags>(entity => modelBuilder.Entity<T_Game_Tags>(entity =>
{ {
entity.HasKey(e => e.Id).HasName("PK_T_CGAME_TAGS"); entity.HasKey(e => e.Id).HasName("PK_T_CGAME_TAGS");
@ -454,10 +161,15 @@ public partial class CloudGamingGameContext : DbContext
entity.Property(e => e.CreatTime).HasColumnType("datetime"); entity.Property(e => e.CreatTime).HasColumnType("datetime");
entity.Property(e => e.Desc) entity.Property(e => e.Desc)
.HasMaxLength(50) .HasMaxLength(100)
.HasComment("描述")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.IsOnline).HasComment("是否启用");
entity.Property(e => e.OrderId).HasComment("排序Id");
entity.Property(e => e.TagId).HasComment("标签Id");
entity.Property(e => e.TagName) entity.Property(e => e.TagName)
.HasMaxLength(50) .HasMaxLength(50)
.HasComment("标签名称")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.UpdateTime).HasColumnType("datetime"); entity.Property(e => e.UpdateTime).HasColumnType("datetime");
@ -469,17 +181,23 @@ public partial class CloudGamingGameContext : DbContext
entity.ToTable(tb => tb.HasComment("游戏类型")); entity.ToTable(tb => tb.HasComment("游戏类型"));
entity.Property(e => e.CreatTime).HasColumnType("datetime"); entity.Property(e => e.CreatTime)
.HasComment("创建时间")
.HasColumnType("datetime");
entity.Property(e => e.IsOnline).HasComment("是否启用");
entity.Property(e => e.OrderId).HasComment("排序");
entity.Property(e => e.TypeDetails) entity.Property(e => e.TypeDetails)
.HasMaxLength(50) .HasMaxLength(100)
.HasComment("描述")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.TypeId).HasComment("类型Id");
entity.Property(e => e.TypeName) entity.Property(e => e.TypeName)
.HasMaxLength(50) .HasMaxLength(50)
.HasComment("类型名称")
.UseCollation("Chinese_PRC_CI_AS"); .UseCollation("Chinese_PRC_CI_AS");
entity.Property(e => e.TypeNameEn) entity.Property(e => e.UpdateTime)
.HasMaxLength(100) .HasComment("修改时间")
.UseCollation("Chinese_PRC_CI_AS"); .HasColumnType("datetime");
entity.Property(e => e.UpdateTime).HasColumnType("datetime");
}); });

View File

@ -1,23 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 难度列表
/// </summary>
public partial class T_CGame_Difficultys
{
public T_CGame_Difficultys() { }
public virtual int Id { get; set; }
public virtual int DifficultyID { get; set; }
public virtual string? DiffcultyName { get; set; }
public virtual string? Desc { get; set; }
public virtual DateTime? CreatTime { get; set; }
public virtual DateTime? UpdateTime { get; set; }
}

View File

@ -1,37 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 游戏中配置
/// </summary>
public partial class T_GameConfig
{
public T_GameConfig() { }
public virtual int Id { get; set; }
public virtual int? ConfigType { get; set; }
public virtual int? ConfigId { get; set; }
public virtual int? BuyBgImageId { get; set; }
public virtual int? BuyBgUIId { get; set; }
public virtual int? BuySubmitImageId { get; set; }
public virtual int? BuySubmitUIId { get; set; }
public virtual int? BuyBackImageId { get; set; }
public virtual int? BuyBackUIId { get; set; }
public virtual string? VipBuyPopId { get; set; }
public virtual string? BuyPopId { get; set; }
public virtual DateTime? UpdateTime { get; set; }
public virtual string? Desc { get; set; }
}

View File

@ -3,7 +3,7 @@
namespace CloudGaming.GameModel.Db.Db_Game; namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary> /// <summary>
/// 游戏多选保存1 游戏类型 2 游戏标签 3 游戏心得4 游戏介绍 5 游戏操作心得 /// 游戏多选保存
/// </summary> /// </summary>
public partial class T_Game_ChildList public partial class T_Game_ChildList
{ {
@ -11,18 +11,26 @@ public partial class T_Game_ChildList
public virtual int Id { get; set; } public virtual int Id { get; set; }
public virtual string? GameId { get; set; } /// <summary>
/// 游戏Id
/// </summary>
public virtual string GameId { get; set; } = null!;
public virtual int? ChildType { get; set; } /// <summary>
/// 1 游戏类型 2 游戏标签
/// </summary>
public virtual int ChildType { get; set; }
/// <summary>
/// 配置表Id
/// </summary>
public virtual int? ChildId { get; set; } public virtual int? ChildId { get; set; }
public virtual DateTime? UpdateTime { get; set; } /// <summary>
/// 描述
/// </summary>
public virtual string? Desc { get; set; } public virtual string? Desc { get; set; }
public virtual int Odds { get; set; }
/// <summary> /// <summary>
/// 排序Id /// 排序Id
/// </summary> /// </summary>

View File

@ -1,21 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 游戏多选保存1 游戏类型2 游戏标签3 游戏心得 4 游戏介绍5 游戏操作心得
/// </summary>
public partial class T_Game_ChildTypes
{
public T_Game_ChildTypes() { }
public virtual int Id { get; set; }
public virtual int? ChildType { get; set; }
public virtual string? ChildIdName { get; set; }
public virtual DateTime? UpdateTime { get; set; }
public virtual string? Desc { get; set; }
}

View File

@ -1,106 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 游戏桌面配置
/// </summary>
public partial class T_Game_DesktopConfig
{
public T_Game_DesktopConfig() { }
/// <summary>
/// 主键,唯一标识
/// </summary>
public virtual int Id { get; set; }
/// <summary>
/// 游戏ID
/// </summary>
public virtual string GameId { get; set; } = null!;
/// <summary>
/// 游戏名称
/// </summary>
public virtual string GameName { get; set; } = null!;
/// <summary>
/// 背景图片
/// </summary>
public virtual int? BackGroundImage { get; set; }
/// <summary>
/// 重新启动图片
/// </summary>
public virtual int? RestartImage { get; set; }
/// <summary>
/// 重新启动图片Top
/// </summary>
public virtual string? RestartImageStyleTop { get; set; }
/// <summary>
/// 重新启动图片Left
/// </summary>
public virtual string? RestartImageStyleLeft { get; set; }
/// <summary>
/// 断开连接图片
/// </summary>
public virtual int? StopImage { get; set; }
/// <summary>
/// 断开连接图片Top
/// </summary>
public virtual string? StopImageStyleTop { get; set; }
/// <summary>
/// 断开连接图片Left
/// </summary>
public virtual string? StopImageStyleLeft { get; set; }
/// <summary>
/// Steam图片
/// </summary>
public virtual int? SteamImage { get; set; }
/// <summary>
/// Steam图片样式
/// </summary>
public virtual string? SteamImageStyleTop { get; set; }
/// <summary>
/// Steam图片样式
/// </summary>
public virtual string? SteamImageStyleLeft { get; set; }
/// <summary>
/// 启动路径
/// </summary>
public virtual string? StartPath { get; set; }
/// <summary>
/// 启动参数
/// </summary>
public virtual string? StartArgs { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public virtual DateTime? CreateTime { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public virtual DateTime? UpdateTime { get; set; }
/// <summary>
/// 创建人
/// </summary>
public virtual string? CreateUserName { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public virtual string? UpdateUserName { get; set; }
}

View File

@ -1,23 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 游戏开发商公司
/// </summary>
public partial class T_Game_DeveloperCompanys
{
public T_Game_DeveloperCompanys() { }
public virtual int Id { get; set; }
public virtual int? CompanyId { get; set; }
public virtual string? CompanyName { get; set; }
public virtual DateTime? UpdateTime { get; set; }
public virtual DateTime? CreatTime { get; set; }
public virtual string? Desc { get; set; }
}

View File

@ -1,23 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 开发商
/// </summary>
public partial class T_Game_Developers
{
public T_Game_Developers() { }
public virtual int ID { get; set; }
public virtual int DeveloperId { get; set; }
public virtual string? DeveloperName { get; set; }
public virtual string? Desc { get; set; }
public virtual DateTime? CreatTime { get; set; }
public virtual DateTime? UpdateTime { get; set; }
}

View File

@ -1,23 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 发行方信息
/// </summary>
public partial class T_Game_Issuers
{
public T_Game_Issuers() { }
public virtual int Id { get; set; }
public virtual int IssuerId { get; set; }
public virtual string? IssuerName { get; set; }
public virtual string? Desc { get; set; }
public virtual DateTime? CreatTime { get; set; }
public virtual DateTime? UpdateTime { get; set; }
}

View File

@ -9,75 +9,61 @@ public partial class T_Game_List
{ {
public T_Game_List() { } public T_Game_List() { }
public virtual int ID { get; set; } public virtual int Id { get; set; }
/// <summary> /// <summary>
/// 我们自己的游戏Id /// 我们自己的游戏Id
/// </summary> /// </summary>
public virtual string GameId { get; set; } = null!; public virtual string GameId { get; set; } = null!;
public virtual string? GameName { get; set; } /// <summary>
/// 游戏名称
/// </summary>
public virtual string GameName { get; set; } = null!;
public virtual int? GameDifficultyId { get; set; } /// <summary>
/// 游戏人数
/// </summary>
public virtual int GamePeopleNum { get; set; }
public virtual int? GamePeopleNum { get; set; } /// <summary>
/// 是否存档
public virtual bool? GameIsSaveFile { get; set; } /// </summary>
public virtual bool GameIsSaveFile { get; set; }
/// <summary> /// <summary>
/// 游戏是否破解 /// 游戏是否破解
/// </summary> /// </summary>
public virtual bool? GameIsCrack { get; set; } public virtual bool GameIsCrack { get; set; }
/// <summary> /// <summary>
/// 游戏是否适配 /// 游戏是否适配
/// </summary> /// </summary>
public virtual bool? GameIsAdapter { get; set; } public virtual bool GameIsAdapter { get; set; }
/// <summary> /// <summary>
/// 游戏是否有版权 /// 游戏是否有版权
/// </summary> /// </summary>
public virtual bool? GameIsVersion { get; set; } public virtual bool GameIsVersion { get; set; }
/// <summary> /// <summary>
/// 游戏版本号 /// 云游戏Id
/// </summary>
public virtual string? GameVersionNum { get; set; }
/// <summary>
/// 游戏版本详情
/// </summary>
public virtual string? GameVersionDesc { get; set; }
/// <summary>
/// 游戏发行方
/// </summary>
public virtual string? GameIssuerId { get; set; }
/// <summary>
/// 游戏是否开发
/// </summary>
public virtual bool? GameIsDevelopers { get; set; }
/// <summary>
/// CP游戏Id
/// </summary> /// </summary>
public virtual string? GameCloudId { get; set; } public virtual string? GameCloudId { get; set; }
/// <summary> /// <summary>
/// CP开发公司 /// 游戏排序
/// </summary> /// </summary>
public virtual int? DCompanyId { get; set; }
/// <summary>
/// 游戏开发方
/// </summary>
public virtual int? DeveloperId { get; set; }
public virtual int? OrderId { get; set; } public virtual int? OrderId { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public virtual DateTime? UpdateTime { get; set; } public virtual DateTime? UpdateTime { get; set; }
/// <summary>
/// 备注
/// </summary>
public virtual string? Desc { get; set; } public virtual string? Desc { get; set; }
/// <summary> /// <summary>
@ -85,47 +71,43 @@ public partial class T_Game_List
/// </summary> /// </summary>
public virtual string? GameIntroduce { get; set; } public virtual string? GameIntroduce { get; set; }
public virtual string? GameSize { get; set; }
/// <summary>
/// 配对id用来放置合作游戏方游戏id如方块科技之类的
/// </summary>
public virtual string CPId { get; set; } = null!;
/// <summary>
/// 配对合作方公司
/// </summary>
public virtual string CPCompany { get; set; } = null!;
/// <summary>
/// 配对第三方游戏是否免费0:免费,1收费
/// </summary>
public virtual int CPIsFree { get; set; }
/// <summary> /// <summary>
/// 屏幕方向0-横屏 1-竖屏 /// 屏幕方向0-横屏 1-竖屏
/// </summary> /// </summary>
public virtual int ScreenOrientation { get; set; } public virtual int ScreenOrientation { get; set; }
/// <summary>
/// 服务器模式0容器1云桌面3海马云
/// </summary>
public virtual int? ServerPattern { get; set; }
/// <summary> /// <summary>
/// 是否有版号 /// 是否有版号
/// </summary> /// </summary>
public virtual bool? GameIsEditionNumber { get; set; } public virtual bool GameIsEditionNumber { get; set; }
/// <summary>
/// 游戏推荐
/// </summary>
public virtual string? GameRecommend { get; set; }
/// <summary> /// <summary>
/// 是否隐藏鼠标 /// 是否隐藏鼠标
/// </summary> /// </summary>
public virtual bool? GameIsEditionMouse { get; set; } public virtual bool GameIsEditionMouse { get; set; }
/// <summary>
/// steam
/// </summary>
public virtual string? SteamId { get; set; } public virtual string? SteamId { get; set; }
/// <summary>
/// 游戏难度
/// </summary>
public virtual string GameDifficulty { get; set; } = null!;
/// <summary>
/// 游戏发行方
/// </summary>
public virtual string? GameIssuer { get; set; }
/// <summary>
/// 云开发公司
/// </summary>
public virtual string? DCompany { get; set; }
/// <summary>
/// 游戏操作类型
/// </summary>
public virtual string? GameOperationModel { get; set; }
} }

View File

@ -1,23 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 游戏操作类型
/// </summary>
public partial class T_Game_OperationModes
{
public T_Game_OperationModes() { }
public virtual int Id { get; set; }
public virtual int OperationModeId { get; set; }
public virtual string Name { get; set; } = null!;
public virtual string? Desc { get; set; }
public virtual DateTime? CreatTime { get; set; }
public virtual DateTime? UpdateTime { get; set; }
}

View File

@ -1,36 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 预加载游戏
/// </summary>
public partial class T_Game_Preload
{
public T_Game_Preload() { }
/// <summary>
/// 自增
/// </summary>
public virtual int Id { get; set; }
/// <summary>
/// 游戏Id
/// </summary>
public virtual string GameId { get; set; } = null!;
/// <summary>
/// 预加载数量
/// </summary>
public virtual int PreloadSum { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public virtual DateTime CreateTime { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public virtual DateTime UpdateTime { get; set; }
}

View File

@ -1,45 +0,0 @@
using System;
namespace CloudGaming.GameModel.Db.Db_Game;
/// <summary>
/// 游戏设置配置
/// </summary>
public partial class T_Game_Setting
{
public T_Game_Setting() { }
public virtual int Id { get; set; }
/// <summary>
/// 设置Id
/// </summary>
public virtual int? SettingId { get; set; }
/// <summary>
/// 设置名字
/// </summary>
public virtual string? Name { get; set; }
/// <summary>
/// 设置排序
/// </summary>
public virtual int? OrderId { get; set; }
/// <summary>
/// 是否显示
/// </summary>
public virtual bool? IsOnline { get; set; }
public virtual DateTime? CreateTime { get; set; }
public virtual DateTime? UpdateTime { get; set; }
public virtual string? Desc { get; set; }
public virtual bool? IsOptional { get; set; }
public virtual int? ImageId { get; set; }
public virtual int? Grade { get; set; }
}

View File

@ -11,13 +11,32 @@ public partial class T_Game_Tags
public virtual int Id { get; set; } public virtual int Id { get; set; }
public virtual int TagID { get; set; } /// <summary>
/// 标签Id
/// </summary>
public virtual int TagId { get; set; }
/// <summary>
/// 标签名称
/// </summary>
public virtual string TagName { get; set; } = null!; public virtual string TagName { get; set; } = null!;
/// <summary>
/// 描述
/// </summary>
public virtual string? Desc { get; set; } public virtual string? Desc { get; set; }
public virtual DateTime? CreatTime { get; set; } public virtual DateTime? CreatTime { get; set; }
public virtual DateTime? UpdateTime { get; set; } public virtual DateTime? UpdateTime { get; set; }
/// <summary>
/// 是否启用
/// </summary>
public virtual bool IsOnline { get; set; }
/// <summary>
/// 排序Id
/// </summary>
public virtual int OrderId { get; set; }
} }

View File

@ -11,21 +11,38 @@ public partial class T_Game_Types
public virtual int Id { get; set; } public virtual int Id { get; set; }
/// <summary>
/// 类型Id
/// </summary>
public virtual int TypeId { get; set; } public virtual int TypeId { get; set; }
/// <summary>
/// 类型名称
/// </summary>
public virtual string TypeName { get; set; } = null!; public virtual string TypeName { get; set; } = null!;
/// <summary>
/// 描述
/// </summary>
public virtual string? TypeDetails { get; set; } public virtual string? TypeDetails { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public virtual DateTime? CreatTime { get; set; } public virtual DateTime? CreatTime { get; set; }
/// <summary>
/// 修改时间
/// </summary>
public virtual DateTime? UpdateTime { get; set; } public virtual DateTime? UpdateTime { get; set; }
public virtual int? Type { get; set; } /// <summary>
/// 排序
/// </summary>
public virtual int OrderId { get; set; }
public virtual int? OrderId { get; set; } /// <summary>
/// 是否启用
public virtual bool? IsOnline { get; set; } /// </summary>
public virtual bool IsOnline { get; set; }
public virtual string? TypeNameEn { get; set; }
} }

View File

@ -16,126 +16,136 @@ namespace HuanMeng.DotNetCore.Utility;
public static class ObjectExtensions public static class ObjectExtensions
{ {
/// <summary> /// <summary>
/// 线程安全的缓存,用于存储每个类型的属性访问器数组 /// 用于存储每种类型的属性访问器数组的线程安全缓存。
/// </summary> /// </summary>
private static readonly ConcurrentDictionary<Type, PropertyAccessor[]> PropertyCache = new(); private static readonly ConcurrentDictionary<Type, PropertyAccessor[]> PropertyCache = new();
/// <summary> /// <summary>
/// 缓存每个属性是否具有 ImagesAttribute 特性 /// 缓存每个属性是否具有 ImagesAttribute 特性
/// </summary> /// </summary>
public static readonly ConcurrentDictionary<PropertyInfo, bool> _PropertyCache = new(); public static readonly ConcurrentDictionary<PropertyInfo, bool> _PropertyCache = new();
/// <summary> /// <summary>
/// 判断对象是否为原始类型或字符串类型 /// 判断对象是否为原始类型或字符串类型
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj">要检查的对象。</param>
/// <returns></returns> /// <returns>如果对象是原始类型或字符串,返回 true否则返回 false。</returns>
public static bool IsPrimitiveType(object obj) => public static bool IsPrimitiveType(object obj) =>
obj is not null && (obj.GetType().IsPrimitive || obj is string or ValueType); obj is not null && (obj.GetType().IsPrimitive || obj is string or ValueType);
/// <summary> /// <summary>
/// 判断对象是否为集合类型(但排除字符串) /// 判断对象是否为集合类型(不包括字符串)。
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj">要检查的对象。</param>
/// <returns></returns> /// <returns>如果对象是集合类型(但不是字符串),返回 true否则返回 false。</returns>
public static bool IsCollectionType(object obj) => obj is IEnumerable && obj is not string; public static bool IsCollectionType(object obj) => obj is IEnumerable && obj is not string;
/// <summary> /// <summary>
/// 将对象转换为字典或列表 /// 根据对象类型,将对象转换为字典或列表格式,支持可选的路径前缀。
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj">要转换的对象。</param>
/// <returns></returns> /// <param name="prefix">属性路径的可选前缀。</param>
public static object ToDictionaryOrList(this object obj) /// <returns>对象的字典或列表表示形式。</returns>
public static object ToDictionaryOrList(this object obj, string prefix = "")
{ {
if (obj == null) return null; if (obj == null) return null;
return obj switch return obj switch
{ {
// 如果是原始类型,直接返回对象
_ when IsPrimitiveType(obj) => obj, _ when IsPrimitiveType(obj) => obj,
// 如果是集合类型,转换为列表 IEnumerable enumerable => TransformCollection(enumerable, prefix),
IEnumerable enumerable => TransformCollection(enumerable), _ => TransformObject(obj, prefix)
// 否则,将对象转换为字典
_ => TransformObject(obj)
}; };
} }
/// <summary> /// <summary>
/// 将集合类型转换为列表 /// 将集合对象转换为包含转换项的列表,每个项保留其路径前缀。
/// </summary> /// </summary>
/// <param name="enumerable"></param> /// <param name="enumerable">要转换的集合。</param>
/// <returns></returns> /// <param name="prefix">集合中每个属性路径的前缀。</param>
private static List<object> TransformCollection(IEnumerable enumerable) /// <returns>转换后的项列表。</returns>
private static List<object> TransformCollection(IEnumerable enumerable, string prefix = "")
{ {
// 如果集合实现了 ICollection 接口,使用其 Count 属性初始化列表容量
var list = new List<object>(enumerable is ICollection collection ? collection.Count : 10); var list = new List<object>(enumerable is ICollection collection ? collection.Count : 10);
int index = 0;
foreach (var item in enumerable) foreach (var item in enumerable)
{ {
// 递归调用 ToDictionaryOrList 对集合中的每个项进行转换 list.Add(ToDictionaryOrList(item, $"{prefix}.[{index}]")); // 为集合中每个项添加路径
list.Add(ToDictionaryOrList(item)); index++;
} }
return list; return list;
} }
/// <summary> /// <summary>
/// 将对象的属性转换为字典 /// 将对象的属性转换为带有路径前缀的字典,并应用前缀规则。
/// </summary> /// </summary>
/// <param name="obj"></param> /// <param name="obj">要转换的对象。</param>
/// <returns></returns> /// <param name="prefix">每个属性路径的前缀。</param>
/// <returns>包含属性名和属性值的字典。</returns>
private static Dictionary<string, object> TransformObject(object obj, string prefix = "") private static Dictionary<string, object> TransformObject(object obj, string prefix = "")
{ {
if (obj == null)
{
return null;
}
var type = obj.GetType(); var type = obj.GetType();
// 获取或创建该类型的属性访问器数组
var accessors = PropertyCache.GetOrAdd(type, CreatePropertyAccessors); var accessors = PropertyCache.GetOrAdd(type, CreatePropertyAccessors);
var keyValuePairs = new Dictionary<string, object>(accessors.Length); var keyValuePairs = new Dictionary<string, object>(accessors.Length);
foreach (var accessor in accessors) foreach (var accessor in accessors)
{ {
// 通过属性访问器获取属性值 var propertyPath = $"{prefix}.{accessor.PropertyName}"; // 构建完整的属性路径
// 使用访问器获取属性值
var propertyValue = accessor.Getter(obj); var propertyValue = accessor.Getter(obj);
// 如果属性是字符串类型,添加 "test" 前缀 // 如果属性是字符串,在其值前添加 "test"
if (propertyValue is string stringValue) if (propertyValue is string stringValue)
{ {
//propertyValue =;
keyValuePairs[accessor.PropertyName] = $"test{stringValue}"; keyValuePairs[accessor.PropertyName] = $"test{stringValue}";
Console.WriteLine(propertyPath);
continue; continue;
} }
// 如果属性有 ImagesAttribute 特性,值前面加上 "image" 前缀 // 如果属性具有 ImagesAttribute在其值前添加 "image"
// 否则,如果属性是集合类型,递归转换 // 否则,如果是集合类型,递归转换
keyValuePairs[accessor.PropertyName] = accessor.HasImagesAttribute keyValuePairs[accessor.PropertyName] = accessor.HasImagesAttribute
? $"image{propertyValue}" ? $"image{propertyValue}"
: IsCollectionType(propertyValue) ? ToDictionaryOrList(propertyValue) : propertyValue; : IsCollectionType(propertyValue) ? ToDictionaryOrList(propertyValue, propertyPath) : propertyValue;
} }
return keyValuePairs; return keyValuePairs;
} }
// 为给定类型创建属性访问器数组 /// <summary>
/// 为给定类型创建属性访问器数组。
/// </summary>
/// <param name="type">要创建属性访问器的类型。</param>
/// <returns>属性访问器数组。</returns>
private static PropertyAccessor[] CreatePropertyAccessors(Type type) private static PropertyAccessor[] CreatePropertyAccessors(Type type)
{ {
var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
return properties.Select(property => return properties.Select(property =>
{ {
// 创建属性的 Getter 委托 // 创建用于访问属性的委托
var getter = CreatePropertyGetter(type, property); var getter = CreatePropertyGetter(type, property);
// 使用缓存检查属性是否具有 ImagesAttribute 特性 // 检查属性是否具有 ImagesAttribute并将结果存储在缓存中
bool hasImagesAttribute = _PropertyCache.GetOrAdd(property, p => p.GetCustomAttribute<ImagesAttribute>() != null); bool hasImagesAttribute = _PropertyCache.GetOrAdd(property, p => p.GetCustomAttribute<ImagesAttribute>() != null);
return new PropertyAccessor(property.Name, getter, hasImagesAttribute); return new PropertyAccessor(property.Name, getter, hasImagesAttribute);
}).ToArray(); }).ToArray();
} }
// 创建用于获取属性值的委托
private static Func<object, object> CreatePropertyGetter(Type type, PropertyInfo property) private static Func<object, object> CreatePropertyGetter(Type type, PropertyInfo property)
{ {
var parameter = Expression.Parameter(typeof(object), "obj"); // 创建参数表达式 var parameter = Expression.Parameter(typeof(object), "obj");
var castParameter = Expression.Convert(parameter, type); // 将参数转换为目标类型 var castParameter = Expression.Convert(parameter, type);
var propertyAccess = Expression.Property(castParameter, property); // 获取属性值 var propertyAccess = Expression.Property(castParameter, property);
var convertPropertyAccess = Expression.Convert(propertyAccess, typeof(object)); // 转换属性值为 object var convertPropertyAccess = Expression.Convert(propertyAccess, typeof(object));
return Expression.Lambda<Func<object, object>>(convertPropertyAccess, parameter).Compile(); // 编译为委托 return Expression.Lambda<Func<object, object>>(convertPropertyAccess, parameter).Compile();
} }
// 属性访问器类包含属性名、Getter 和特性标志
private class PropertyAccessor private class PropertyAccessor
{ {
public string PropertyName { get; } public string PropertyName { get; }
@ -151,7 +161,6 @@ public static class ObjectExtensions
} }
} }
[Obsolete] [Obsolete]
public static class ObjectExtensions11 public static class ObjectExtensions11
{ {