diff --git a/src/CloudGaming/Code/CloudGaming.Code/Cache/CloudGamingCache.cs b/src/CloudGaming/Code/CloudGaming.Code/Cache/CloudGamingCache.cs index 6ac9abb..8f9f802 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Cache/CloudGamingCache.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Cache/CloudGamingCache.cs @@ -63,6 +63,17 @@ namespace CloudGaming.Code.Cache /// 菜单分类 /// public List EpgCategoryCfg => GetCacheList(ref _epgCategoryCfg, it => it.IsOnline); + #endregion + + #region 首页缓存表 + + //private CommonDataEntityCache? _gameList; + + ///// + ///// 菜单分类 + ///// + //public List GameList => GetCacheList(ref _gameList); + #endregion } diff --git a/src/CloudGaming/Code/CloudGaming.Code/Epg/EpgBLL.cs b/src/CloudGaming/Code/CloudGaming.Code/Epg/EpgBLL.cs index 917d42b..4bab5bb 100644 --- a/src/CloudGaming/Code/CloudGaming.Code/Epg/EpgBLL.cs +++ b/src/CloudGaming/Code/CloudGaming.Code/Epg/EpgBLL.cs @@ -1,3 +1,4 @@ +using CloudGaming.Code.Cache; using CloudGaming.DtoModel.Epg; using System; @@ -24,7 +25,7 @@ namespace CloudGaming.Code.Epg /// public async Task> GetHomeInfo() { - var listQueryable = GetEpgCategory("Home").AsQueryable(); + var listQueryable = GetEpgCategory(EpgEnum.EpgCatIdName.大厅首页).AsQueryable(); if (IsChecking) { listQueryable = listQueryable.Where(it => it.ShowStatus == 0 || it.ShowStatus == 2).AsQueryable(); @@ -38,22 +39,46 @@ namespace CloudGaming.Code.Epg List epgCategoryDtos = new List(); list.ForEach(it => { - EpgCategoryDto epgCategoryDto = new EpgCategoryDto() + var list = new List() { - CategoryName = it.Name, - CategoryType = it.IdName, - IsQuickStartPopUp = it.IsQuickStartPopUp ?? false, - ShowNum_Index = it.ShowNumIndex ?? 0, - EpgList = new List() - { - }, }; - 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; } @@ -71,5 +96,22 @@ namespace CloudGaming.Code.Epg } return new List(); } + + /// + /// + /// + /// + /// + public List GetEpgList(int epgParentCategoryId) + { + var list = CloudGamingCacheExtend.GetDataEntityCache(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; + } } } diff --git a/src/CloudGaming/Console/CloudGaming.Test/ToDictionaryOrListTest.cs b/src/CloudGaming/Console/CloudGaming.Test/ToDictionaryOrListTest.cs index d8fdd4d..1d44763 100644 --- a/src/CloudGaming/Console/CloudGaming.Test/ToDictionaryOrListTest.cs +++ b/src/CloudGaming/Console/CloudGaming.Test/ToDictionaryOrListTest.cs @@ -25,7 +25,7 @@ namespace CloudGaming.Test } - //[Benchmark] + [Benchmark] public object ObjectToDictionaryOrListTest1() { EpgCategoryDto epgCategoryDto = new EpgCategoryDto() @@ -52,7 +52,7 @@ namespace CloudGaming.Test } - //[Benchmark] + [Benchmark] public object ListToDictionaryOrListTest1() { @@ -221,7 +221,7 @@ namespace CloudGaming.Test } - [Benchmark] + // [Benchmark] public object ObjectToDictionaryOrListExtend4() { EpgCategoryDto epgCategoryDto = new EpgCategoryDto() @@ -247,7 +247,7 @@ namespace CloudGaming.Test } - [Benchmark] + //[Benchmark] public object ListToDictionaryOrListExtend4() { List epgCategoryDtos = new List(); @@ -285,7 +285,7 @@ namespace CloudGaming.Test } - [Benchmark] + //[Benchmark] public object ObjectToDictionaryOrListExtend6() { EpgCategoryDto epgCategoryDto = new EpgCategoryDto() @@ -310,8 +310,8 @@ namespace CloudGaming.Test } - - [Benchmark] + // + //[Benchmark] public object ListToDictionaryOrListExtend6() { List epgCategoryDtos = new List(); @@ -349,7 +349,7 @@ namespace CloudGaming.Test } - [Benchmark] + //[Benchmark] public object ObjectToDictionaryOrListExtend7() { EpgCategoryDto epgCategoryDto = new EpgCategoryDto() @@ -375,7 +375,7 @@ namespace CloudGaming.Test } - [Benchmark] + //[Benchmark] public object ListToDictionaryOrListExtend7() { List epgCategoryDtos = new List(); @@ -412,7 +412,7 @@ namespace CloudGaming.Test return dic; } - [Benchmark] + //[Benchmark] public object ObjectToDictionaryOrListExtend8() { EpgCategoryDto epgCategoryDto = new EpgCategoryDto() @@ -438,7 +438,7 @@ namespace CloudGaming.Test } - [Benchmark] + // [Benchmark] public object ListToDictionaryOrListExtend8() { List epgCategoryDtos = new List(); diff --git a/src/CloudGaming/Model/CloudGaming.DtoModel/Epg/EpgEnum.cs b/src/CloudGaming/Model/CloudGaming.DtoModel/Epg/EpgEnum.cs new file mode 100644 index 0000000..9158dd1 --- /dev/null +++ b/src/CloudGaming/Model/CloudGaming.DtoModel/Epg/EpgEnum.cs @@ -0,0 +1,143 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CloudGaming.DtoModel.Epg +{ + /// + /// Epg配置相关枚举 + /// + public class EpgEnum + { + /// + /// 常用epg分组-标识IdName + /// + 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"; + } + + + /// + /// 资源图片样式,尺寸 + /// + public enum ImageResStyle + { + /// + /// 游戏-尊享推荐, 竖版 Image_Shu + /// + Game尊享推荐_312_420 = 1, + + /// + /// 游戏-推荐位大图 Image_Block2 + /// + Game推荐位大图_984_520 = 2, + /// + /// 游戏-精选推荐, 豆腐块图 Image_Block + /// + Game精选推荐_474_300 = 3, + /// + /// 游戏-最近推出, 竖版2,高一点的(最近推出) Image_Shu2 + /// + Game最近推出_360_548 = 4, + + /// + /// 游戏-游戏库, 正方形 (GameImageId) + /// + Game游戏库_180_180 = 5, + } + + + /// + /// 资源类型 + /// + public enum EpgResType + { + /// + /// 没有特殊说明作用,一般用来标记下 + /// + 未定义 = 0, + /// + /// 对应游戏Id + /// + 游戏 = 4, + 充值界面 = 7, + 产品充值 = 8, + /// + /// 对应H5地址 + /// + H5页面 = 9, + /// + /// 对应浏览器地址(IOS专用) + /// + 外部浏览器 = 10, + /// + /// 对应游戏id, 跳到游戏房间界面,为空则进联机大厅 + /// + 对战专区游戏 = 11, + /// + /// 对应H5地址——原生地址 + /// + H5页面_原生 = 12, + /// + /// 对应栏目标识:如SubjectIndex,Task,Activity,History等 + /// + 栏目界面 = 21, + /// + /// 对应弹窗Id,显示对应的弹窗 + /// + 弹窗 = 101, + } + + + /// + /// 客户端的跳转类型 + /// 示例:holybladeData={"dataType":9,"dataId":"https://moguext.moguyouxi.cn/moguext/ui/bbs/autologin"} + /// + public enum JumpDataType + { + /// + /// dataId=咨询Id + /// + 资讯 = 1, + 攻略 = 2, + 测评 = 3, + 游戏 = 4, + 专题 = 5, + /// + /// 应该不用了 + /// + 活动 = 6, + + /// + /// dataId无 + /// + 钻石加油包 = 7, + /// + /// dataId无 + /// + 会员购买 = 8, + + /// + /// dataId=h5页面完整地址 + /// + 跳转到h5页面 = 9, + } + + } + +} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/CloudGamingGameContext.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/CloudGamingGameContext.cs index 29e1fde..0852c7f 100644 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/CloudGamingGameContext.cs +++ b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/CloudGamingGameContext.cs @@ -45,65 +45,15 @@ public partial class CloudGamingGameContext : DbContext /// - /// 难度列表 - /// - public virtual DbSet T_CGame_Difficultys { get; set; } - - /// - /// 游戏中配置 - /// - public virtual DbSet T_GameConfig { get; set; } - - /// - /// 游戏多选保存1 游戏类型 2 游戏标签 3 游戏心得4 游戏介绍 5 游戏操作心得 + /// 游戏多选保存 /// public virtual DbSet T_Game_ChildList { get; set; } - /// - /// 游戏多选保存1 游戏类型2 游戏标签3 游戏心得 4 游戏介绍5 游戏操作心得 - /// - public virtual DbSet T_Game_ChildTypes { get; set; } - - /// - /// 游戏桌面配置 - /// - public virtual DbSet T_Game_DesktopConfig { get; set; } - - /// - /// 游戏开发商公司 - /// - public virtual DbSet T_Game_DeveloperCompanys { get; set; } - - /// - /// 开发商 - /// - public virtual DbSet T_Game_Developers { get; set; } - - /// - /// 发行方信息 - /// - public virtual DbSet T_Game_Issuers { get; set; } - /// /// 游戏列表 /// public virtual DbSet T_Game_List { get; set; } - /// - /// 游戏操作类型 - /// - public virtual DbSet T_Game_OperationModes { get; set; } - - /// - /// 预加载游戏 - /// - public virtual DbSet T_Game_Preload { get; set; } - - /// - /// 游戏设置配置 - /// - public virtual DbSet T_Game_Setting { get; set; } - /// /// 游戏标签 /// @@ -124,220 +74,46 @@ public partial class CloudGamingGameContext : DbContext protected override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity(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(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(entity => { 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) .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.OrderId).HasComment("排序Id"); - entity.Property(e => e.UpdateTime).HasColumnType("datetime"); - - }); - - modelBuilder.Entity(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(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(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(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(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(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.Property(e => e.CPCompany) + entity.Property(e => e.DCompany) .HasMaxLength(50) - .HasDefaultValue("") - .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开发公司"); + .HasComment("云开发公司"); entity.Property(e => e.Desc) .HasMaxLength(100) + .HasComment("备注") .UseCollation("Chinese_PRC_CI_AS"); - entity.Property(e => e.DeveloperId).HasComment("游戏开发方"); entity.Property(e => e.GameCloudId) .HasMaxLength(50) - .HasComment("CP游戏Id") + .HasComment("云游戏Id") .UseCollation("Chinese_PRC_CI_AS"); + entity.Property(e => e.GameDifficulty) + .HasMaxLength(10) + .HasComment("游戏难度"); entity.Property(e => e.GameId) .HasMaxLength(100) .HasComment("我们自己的游戏Id") @@ -347,105 +123,36 @@ public partial class CloudGamingGameContext : DbContext .UseCollation("Chinese_PRC_CI_AS"); entity.Property(e => e.GameIsAdapter).HasComment("游戏是否适配"); entity.Property(e => e.GameIsCrack).HasComment("游戏是否破解"); - entity.Property(e => e.GameIsDevelopers).HasComment("游戏是否开发"); entity.Property(e => e.GameIsEditionMouse).HasComment("是否隐藏鼠标"); - entity.Property(e => e.GameIsEditionNumber) - .HasDefaultValue(false) - .HasComment("是否有版号"); + entity.Property(e => e.GameIsEditionNumber).HasComment("是否有版号"); + entity.Property(e => e.GameIsSaveFile).HasComment("是否存档"); entity.Property(e => e.GameIsVersion).HasComment("游戏是否有版权"); - entity.Property(e => e.GameIssuerId) + entity.Property(e => e.GameIssuer) .HasMaxLength(100) .HasComment("游戏发行方") .UseCollation("Chinese_PRC_CI_AS"); entity.Property(e => e.GameName) .HasMaxLength(100) + .HasComment("游戏名称") .UseCollation("Chinese_PRC_CI_AS"); - entity.Property(e => e.GameRecommend) - .HasMaxLength(1000) - .HasComment("游戏推荐") - .UseCollation("Chinese_PRC_CI_AS"); - entity.Property(e => e.GameSize) - .HasMaxLength(100) - .UseCollation("Chinese_PRC_CI_AS"); - 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.GameOperationModel) + .HasMaxLength(255) + .HasComment("游戏操作类型"); + entity.Property(e => e.GamePeopleNum) + .HasDefaultValue(1) + .HasComment("游戏人数"); + entity.Property(e => e.OrderId).HasComment("游戏排序"); entity.Property(e => e.ScreenOrientation).HasComment("屏幕方向:0-横屏 1-竖屏"); - entity.Property(e => e.ServerPattern) - .HasDefaultValue(0) - .HasComment("服务器模式:0容器,1云桌面,3海马云"); entity.Property(e => e.SteamId) .HasMaxLength(30) + .HasComment("steam") .UseCollation("Chinese_PRC_CI_AS"); - entity.Property(e => e.UpdateTime).HasColumnType("datetime"); - - }); - - modelBuilder.Entity(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(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) - .HasDefaultValueSql("(getdate())") .HasComment("修改时间") .HasColumnType("datetime"); }); - modelBuilder.Entity(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(entity => { 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.Desc) - .HasMaxLength(50) + .HasMaxLength(100) + .HasComment("描述") .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) .HasMaxLength(50) + .HasComment("标签名称") .UseCollation("Chinese_PRC_CI_AS"); entity.Property(e => e.UpdateTime).HasColumnType("datetime"); @@ -469,17 +181,23 @@ public partial class CloudGamingGameContext : DbContext 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) - .HasMaxLength(50) + .HasMaxLength(100) + .HasComment("描述") .UseCollation("Chinese_PRC_CI_AS"); + entity.Property(e => e.TypeId).HasComment("类型Id"); entity.Property(e => e.TypeName) .HasMaxLength(50) + .HasComment("类型名称") .UseCollation("Chinese_PRC_CI_AS"); - entity.Property(e => e.TypeNameEn) - .HasMaxLength(100) - .UseCollation("Chinese_PRC_CI_AS"); - entity.Property(e => e.UpdateTime).HasColumnType("datetime"); + entity.Property(e => e.UpdateTime) + .HasComment("修改时间") + .HasColumnType("datetime"); }); diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_CGame_Difficultys.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_CGame_Difficultys.cs deleted file mode 100644 index 7b83fe1..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_CGame_Difficultys.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 难度列表 -/// -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; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_GameConfig.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_GameConfig.cs deleted file mode 100644 index e290667..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_GameConfig.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 游戏中配置 -/// -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; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_ChildList.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_ChildList.cs index c11b458..92dc2e1 100644 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_ChildList.cs +++ b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_ChildList.cs @@ -3,7 +3,7 @@ namespace CloudGaming.GameModel.Db.Db_Game; /// -/// 游戏多选保存1 游戏类型 2 游戏标签 3 游戏心得4 游戏介绍 5 游戏操作心得 +/// 游戏多选保存 /// public partial class T_Game_ChildList { @@ -11,18 +11,26 @@ public partial class T_Game_ChildList public virtual int Id { get; set; } - public virtual string? GameId { get; set; } + /// + /// 游戏Id + /// + public virtual string GameId { get; set; } = null!; - public virtual int? ChildType { get; set; } + /// + /// 1 游戏类型 2 游戏标签 + /// + public virtual int ChildType { get; set; } + /// + /// 配置表Id + /// public virtual int? ChildId { get; set; } - public virtual DateTime? UpdateTime { get; set; } - + /// + /// 描述 + /// public virtual string? Desc { get; set; } - public virtual int Odds { get; set; } - /// /// 排序Id /// diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_ChildTypes.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_ChildTypes.cs deleted file mode 100644 index bea9a8b..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_ChildTypes.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 游戏多选保存1 游戏类型2 游戏标签3 游戏心得 4 游戏介绍5 游戏操作心得 -/// -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; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_DesktopConfig.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_DesktopConfig.cs deleted file mode 100644 index 391e3c5..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_DesktopConfig.cs +++ /dev/null @@ -1,106 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 游戏桌面配置 -/// -public partial class T_Game_DesktopConfig -{ - public T_Game_DesktopConfig() { } - - /// - /// 主键,唯一标识 - /// - public virtual int Id { get; set; } - - /// - /// 游戏ID - /// - public virtual string GameId { get; set; } = null!; - - /// - /// 游戏名称 - /// - public virtual string GameName { get; set; } = null!; - - /// - /// 背景图片 - /// - public virtual int? BackGroundImage { get; set; } - - /// - /// 重新启动图片 - /// - public virtual int? RestartImage { get; set; } - - /// - /// 重新启动图片Top - /// - public virtual string? RestartImageStyleTop { get; set; } - - /// - /// 重新启动图片Left - /// - public virtual string? RestartImageStyleLeft { get; set; } - - /// - /// 断开连接图片 - /// - public virtual int? StopImage { get; set; } - - /// - /// 断开连接图片Top - /// - public virtual string? StopImageStyleTop { get; set; } - - /// - /// 断开连接图片Left - /// - public virtual string? StopImageStyleLeft { get; set; } - - /// - /// Steam图片 - /// - public virtual int? SteamImage { get; set; } - - /// - /// Steam图片样式 - /// - public virtual string? SteamImageStyleTop { get; set; } - - /// - /// Steam图片样式 - /// - public virtual string? SteamImageStyleLeft { get; set; } - - /// - /// 启动路径 - /// - public virtual string? StartPath { get; set; } - - /// - /// 启动参数 - /// - public virtual string? StartArgs { get; set; } - - /// - /// 创建时间 - /// - public virtual DateTime? CreateTime { get; set; } - - /// - /// 修改时间 - /// - public virtual DateTime? UpdateTime { get; set; } - - /// - /// 创建人 - /// - public virtual string? CreateUserName { get; set; } - - /// - /// 创建时间 - /// - public virtual string? UpdateUserName { get; set; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_DeveloperCompanys.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_DeveloperCompanys.cs deleted file mode 100644 index 9889f9e..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_DeveloperCompanys.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 游戏开发商公司 -/// -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; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Developers.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Developers.cs deleted file mode 100644 index abcb7d8..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Developers.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 开发商 -/// -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; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Issuers.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Issuers.cs deleted file mode 100644 index fbbecef..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Issuers.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 发行方信息 -/// -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; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_List.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_List.cs index 9e89d3d..5e1e2f0 100644 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_List.cs +++ b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_List.cs @@ -9,75 +9,61 @@ public partial class T_Game_List { public T_Game_List() { } - public virtual int ID { get; set; } + public virtual int Id { get; set; } /// /// 我们自己的游戏Id /// public virtual string GameId { get; set; } = null!; - public virtual string? GameName { get; set; } + /// + /// 游戏名称 + /// + public virtual string GameName { get; set; } = null!; - public virtual int? GameDifficultyId { get; set; } + /// + /// 游戏人数 + /// + public virtual int GamePeopleNum { get; set; } - public virtual int? GamePeopleNum { get; set; } - - public virtual bool? GameIsSaveFile { get; set; } + /// + /// 是否存档 + /// + public virtual bool GameIsSaveFile { get; set; } /// /// 游戏是否破解 /// - public virtual bool? GameIsCrack { get; set; } + public virtual bool GameIsCrack { get; set; } /// /// 游戏是否适配 /// - public virtual bool? GameIsAdapter { get; set; } + public virtual bool GameIsAdapter { get; set; } /// /// 游戏是否有版权 /// - public virtual bool? GameIsVersion { get; set; } + public virtual bool GameIsVersion { get; set; } /// - /// 游戏版本号 - /// - public virtual string? GameVersionNum { get; set; } - - /// - /// 游戏版本详情 - /// - public virtual string? GameVersionDesc { get; set; } - - /// - /// 游戏发行方 - /// - public virtual string? GameIssuerId { get; set; } - - /// - /// 游戏是否开发 - /// - public virtual bool? GameIsDevelopers { get; set; } - - /// - /// CP游戏Id + /// 云游戏Id /// public virtual string? GameCloudId { get; set; } /// - /// CP开发公司 + /// 游戏排序 /// - public virtual int? DCompanyId { get; set; } - - /// - /// 游戏开发方 - /// - public virtual int? DeveloperId { get; set; } - public virtual int? OrderId { get; set; } + /// + /// 修改时间 + /// public virtual DateTime? UpdateTime { get; set; } + /// + /// 备注 + /// public virtual string? Desc { get; set; } /// @@ -85,47 +71,43 @@ public partial class T_Game_List /// public virtual string? GameIntroduce { get; set; } - public virtual string? GameSize { get; set; } - - /// - /// 配对id(用来放置合作游戏方游戏id,如方块科技之类的) - /// - public virtual string CPId { get; set; } = null!; - - /// - /// 配对合作方公司 - /// - public virtual string CPCompany { get; set; } = null!; - - /// - /// 配对第三方游戏是否免费0:免费,1:收费 - /// - public virtual int CPIsFree { get; set; } - /// /// 屏幕方向:0-横屏 1-竖屏 /// public virtual int ScreenOrientation { get; set; } - /// - /// 服务器模式:0容器,1云桌面,3海马云 - /// - public virtual int? ServerPattern { get; set; } - /// /// 是否有版号 /// - public virtual bool? GameIsEditionNumber { get; set; } - - /// - /// 游戏推荐 - /// - public virtual string? GameRecommend { get; set; } + public virtual bool GameIsEditionNumber { get; set; } /// /// 是否隐藏鼠标 /// - public virtual bool? GameIsEditionMouse { get; set; } + public virtual bool GameIsEditionMouse { get; set; } + /// + /// steam + /// public virtual string? SteamId { get; set; } + + /// + /// 游戏难度 + /// + public virtual string GameDifficulty { get; set; } = null!; + + /// + /// 游戏发行方 + /// + public virtual string? GameIssuer { get; set; } + + /// + /// 云开发公司 + /// + public virtual string? DCompany { get; set; } + + /// + /// 游戏操作类型 + /// + public virtual string? GameOperationModel { get; set; } } diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_OperationModes.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_OperationModes.cs deleted file mode 100644 index a53be1f..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_OperationModes.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 游戏操作类型 -/// -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; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Preload.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Preload.cs deleted file mode 100644 index 36d4acf..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Preload.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 预加载游戏 -/// -public partial class T_Game_Preload -{ - public T_Game_Preload() { } - - /// - /// 自增 - /// - public virtual int Id { get; set; } - - /// - /// 游戏Id - /// - public virtual string GameId { get; set; } = null!; - - /// - /// 预加载数量 - /// - public virtual int PreloadSum { get; set; } - - /// - /// 创建时间 - /// - public virtual DateTime CreateTime { get; set; } - - /// - /// 修改时间 - /// - public virtual DateTime UpdateTime { get; set; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Setting.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Setting.cs deleted file mode 100644 index 8c70341..0000000 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Setting.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; - -namespace CloudGaming.GameModel.Db.Db_Game; - -/// -/// 游戏设置配置 -/// -public partial class T_Game_Setting -{ - public T_Game_Setting() { } - - public virtual int Id { get; set; } - - /// - /// 设置Id - /// - public virtual int? SettingId { get; set; } - - /// - /// 设置名字 - /// - public virtual string? Name { get; set; } - - /// - /// 设置排序 - /// - public virtual int? OrderId { get; set; } - - /// - /// 是否显示 - /// - 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; } -} diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Tags.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Tags.cs index cc0f20a..afac2a2 100644 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Tags.cs +++ b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Tags.cs @@ -11,13 +11,32 @@ public partial class T_Game_Tags public virtual int Id { get; set; } - public virtual int TagID { get; set; } + /// + /// 标签Id + /// + public virtual int TagId { get; set; } + /// + /// 标签名称 + /// public virtual string TagName { get; set; } = null!; + /// + /// 描述 + /// public virtual string? Desc { get; set; } public virtual DateTime? CreatTime { get; set; } public virtual DateTime? UpdateTime { get; set; } + + /// + /// 是否启用 + /// + public virtual bool IsOnline { get; set; } + + /// + /// 排序Id + /// + public virtual int OrderId { get; set; } } diff --git a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Types.cs b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Types.cs index d4b3d47..c7a0fb3 100644 --- a/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Types.cs +++ b/src/CloudGaming/Model/CloudGaming.GameModel/Db/Db_Game/T_Game_Types.cs @@ -11,21 +11,38 @@ public partial class T_Game_Types public virtual int Id { get; set; } + /// + /// 类型Id + /// public virtual int TypeId { get; set; } + /// + /// 类型名称 + /// public virtual string TypeName { get; set; } = null!; + /// + /// 描述 + /// public virtual string? TypeDetails { get; set; } + /// + /// 创建时间 + /// public virtual DateTime? CreatTime { get; set; } + /// + /// 修改时间 + /// public virtual DateTime? UpdateTime { get; set; } - public virtual int? Type { get; set; } + /// + /// 排序 + /// + public virtual int OrderId { get; set; } - public virtual int? OrderId { get; set; } - - public virtual bool? IsOnline { get; set; } - - public virtual string? TypeNameEn { get; set; } + /// + /// 是否启用 + /// + public virtual bool IsOnline { get; set; } } diff --git a/src/CloudGaming/Utile/HuanMeng.DotNetCore/Utility/ObjectExtensions1.cs b/src/CloudGaming/Utile/HuanMeng.DotNetCore/Utility/ObjectExtensions1.cs index 1e907d4..40c5e37 100644 --- a/src/CloudGaming/Utile/HuanMeng.DotNetCore/Utility/ObjectExtensions1.cs +++ b/src/CloudGaming/Utile/HuanMeng.DotNetCore/Utility/ObjectExtensions1.cs @@ -16,126 +16,136 @@ namespace HuanMeng.DotNetCore.Utility; public static class ObjectExtensions { /// - /// 线程安全的缓存,用于存储每个类型的属性访问器数组 + /// 用于存储每种类型的属性访问器数组的线程安全缓存。 /// private static readonly ConcurrentDictionary PropertyCache = new(); + /// - /// 缓存每个属性是否具有 ImagesAttribute 特性 + /// 缓存每个属性是否具有 ImagesAttribute 特性。 /// public static readonly ConcurrentDictionary _PropertyCache = new(); /// - /// 判断对象是否为原始类型或字符串类型 + /// 判断对象是否为原始类型或字符串类型。 /// - /// - /// + /// 要检查的对象。 + /// 如果对象是原始类型或字符串,返回 true;否则返回 false。 public static bool IsPrimitiveType(object obj) => obj is not null && (obj.GetType().IsPrimitive || obj is string or ValueType); /// - /// 判断对象是否为集合类型(但排除字符串) + /// 判断对象是否为集合类型(不包括字符串)。 /// - /// - /// + /// 要检查的对象。 + /// 如果对象是集合类型(但不是字符串),返回 true;否则返回 false。 public static bool IsCollectionType(object obj) => obj is IEnumerable && obj is not string; /// - /// 将对象转换为字典或列表 + /// 根据对象类型,将对象转换为字典或列表格式,支持可选的路径前缀。 /// - /// - /// - public static object ToDictionaryOrList(this object obj) + /// 要转换的对象。 + /// 属性路径的可选前缀。 + /// 对象的字典或列表表示形式。 + public static object ToDictionaryOrList(this object obj, string prefix = "") { if (obj == null) return null; return obj switch { - // 如果是原始类型,直接返回对象 _ when IsPrimitiveType(obj) => obj, - // 如果是集合类型,转换为列表 - IEnumerable enumerable => TransformCollection(enumerable), - // 否则,将对象转换为字典 - _ => TransformObject(obj) + IEnumerable enumerable => TransformCollection(enumerable, prefix), + _ => TransformObject(obj, prefix) }; } /// - /// 将集合类型转换为列表 + /// 将集合对象转换为包含转换项的列表,每个项保留其路径前缀。 /// - /// - /// - private static List TransformCollection(IEnumerable enumerable) + /// 要转换的集合。 + /// 集合中每个属性路径的前缀。 + /// 转换后的项列表。 + private static List TransformCollection(IEnumerable enumerable, string prefix = "") { - // 如果集合实现了 ICollection 接口,使用其 Count 属性初始化列表容量 var list = new List(enumerable is ICollection collection ? collection.Count : 10); + int index = 0; foreach (var item in enumerable) { - // 递归调用 ToDictionaryOrList 对集合中的每个项进行转换 - list.Add(ToDictionaryOrList(item)); + list.Add(ToDictionaryOrList(item, $"{prefix}.[{index}]")); // 为集合中每个项添加路径 + index++; } return list; } /// - /// 将对象的属性转换为字典 + /// 将对象的属性转换为带有路径前缀的字典,并应用前缀规则。 /// - /// - /// + /// 要转换的对象。 + /// 每个属性路径的前缀。 + /// 包含属性名和属性值的字典。 private static Dictionary TransformObject(object obj, string prefix = "") { + if (obj == null) + { + return null; + } var type = obj.GetType(); - // 获取或创建该类型的属性访问器数组 var accessors = PropertyCache.GetOrAdd(type, CreatePropertyAccessors); var keyValuePairs = new Dictionary(accessors.Length); foreach (var accessor in accessors) { - // 通过属性访问器获取属性值 + var propertyPath = $"{prefix}.{accessor.PropertyName}"; // 构建完整的属性路径 + + // 使用访问器获取属性值 var propertyValue = accessor.Getter(obj); - // 如果属性值是字符串类型,添加 "test" 前缀 + // 如果属性是字符串,在其值前添加 "test" if (propertyValue is string stringValue) { - //propertyValue =; keyValuePairs[accessor.PropertyName] = $"test{stringValue}"; + Console.WriteLine(propertyPath); continue; } - // 如果属性有 ImagesAttribute 特性,值前面加上 "image" 前缀 - // 否则,如果属性是集合类型,递归转换 + // 如果属性具有 ImagesAttribute,在其值前添加 "image" + // 否则,如果是集合类型,则递归转换 keyValuePairs[accessor.PropertyName] = accessor.HasImagesAttribute ? $"image{propertyValue}" - : IsCollectionType(propertyValue) ? ToDictionaryOrList(propertyValue) : propertyValue; + : IsCollectionType(propertyValue) ? ToDictionaryOrList(propertyValue, propertyPath) : propertyValue; } return keyValuePairs; } - // 为给定类型创建属性访问器数组 + /// + /// 为给定类型创建属性访问器数组。 + /// + /// 要创建属性访问器的类型。 + /// 属性访问器数组。 private static PropertyAccessor[] CreatePropertyAccessors(Type type) { var properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance); return properties.Select(property => { - // 创建属性的 Getter 委托 + // 创建用于访问属性值的委托 var getter = CreatePropertyGetter(type, property); - // 使用缓存检查属性是否具有 ImagesAttribute 特性 + // 检查属性是否具有 ImagesAttribute,并将结果存储在缓存中 bool hasImagesAttribute = _PropertyCache.GetOrAdd(property, p => p.GetCustomAttribute() != null); return new PropertyAccessor(property.Name, getter, hasImagesAttribute); }).ToArray(); } - // 创建用于获取属性值的委托 + + private static Func CreatePropertyGetter(Type type, PropertyInfo property) { - var parameter = Expression.Parameter(typeof(object), "obj"); // 创建参数表达式 - var castParameter = Expression.Convert(parameter, type); // 将参数转换为目标类型 - var propertyAccess = Expression.Property(castParameter, property); // 获取属性值 - var convertPropertyAccess = Expression.Convert(propertyAccess, typeof(object)); // 转换属性值为 object - return Expression.Lambda>(convertPropertyAccess, parameter).Compile(); // 编译为委托 + var parameter = Expression.Parameter(typeof(object), "obj"); + var castParameter = Expression.Convert(parameter, type); + var propertyAccess = Expression.Property(castParameter, property); + var convertPropertyAccess = Expression.Convert(propertyAccess, typeof(object)); + return Expression.Lambda>(convertPropertyAccess, parameter).Compile(); } - // 属性访问器类,包含属性名、Getter 和特性标志 private class PropertyAccessor { public string PropertyName { get; } @@ -151,7 +161,6 @@ public static class ObjectExtensions } } - [Obsolete] public static class ObjectExtensions11 {