diff --git a/Tiobon.Core.Common/Helper/Appsettings.cs b/Tiobon.Core.Common/Helper/Appsettings.cs index 3d01cce2..21599e43 100644 --- a/Tiobon.Core.Common/Helper/Appsettings.cs +++ b/Tiobon.Core.Common/Helper/Appsettings.cs @@ -1,92 +1,88 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration.Json; -using System; -using System.Collections.Generic; -using System.Linq; -namespace Tiobon.Core.Common +namespace Tiobon.Core.Common; + +/// +/// appsettings.json操作类 +/// +public class AppSettings { - /// - /// appsettings.json操作类 - /// - public class AppSettings - { - public static IConfiguration Configuration { get; set; } - static string contentPath { get; set; } + public static IConfiguration Configuration { get; set; } + static string contentPath { get; set; } - public AppSettings(string contentPath) - { - string Path = "appsettings.json"; + public AppSettings(string contentPath) + { + string Path = "appsettings.json"; - //如果你把配置文件 是 根据环境变量来分开了,可以这样写 - //Path = $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json"; + //如果你把配置文件 是 根据环境变量来分开了,可以这样写 + //Path = $"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json"; - Configuration = new ConfigurationBuilder() - .SetBasePath(contentPath) - .Add(new JsonConfigurationSource - { - Path = Path, Optional = false, ReloadOnChange = true - }) //这样的话,可以直接读目录里的json文件,而不是 bin 文件夹下的,所以不用修改复制属性 - .Build(); - } + Configuration = new ConfigurationBuilder() + .SetBasePath(contentPath) + .Add(new JsonConfigurationSource + { + Path = Path, Optional = false, ReloadOnChange = true + }) //这样的话,可以直接读目录里的json文件,而不是 bin 文件夹下的,所以不用修改复制属性 + .Build(); + } - public AppSettings(IConfiguration configuration) - { - Configuration = configuration; - } + public AppSettings(IConfiguration configuration) + { + Configuration = configuration; + } - /// - /// 封装要操作的字符 - /// - /// 节点配置 - /// - public static string app(params string[] sections) + /// + /// 封装要操作的字符 + /// + /// 节点配置 + /// + public static string app(params string[] sections) + { + try { - try - { - if (sections.Any()) - { - return Configuration[string.Join(":", sections)]; - } - } - catch (Exception) + if (sections.Any()) { + return Configuration[string.Join(":", sections)]; } - - return ""; } - - /// - /// 递归获取配置信息数组 - /// - /// - /// - /// - public static List app(params string[] sections) + catch (Exception) { - List list = new List(); - // 引用 Microsoft.Extensions.Configuration.Binder 包 - Configuration.Bind(string.Join(":", sections), list); - return list; } + return ""; + } + + /// + /// 递归获取配置信息数组 + /// + /// + /// + /// + public static List app(params string[] sections) + { + List list = new List(); + // 引用 Microsoft.Extensions.Configuration.Binder 包 + Configuration.Bind(string.Join(":", sections), list); + return list; + } - /// - /// 根据路径 configuration["App:Name"]; - /// - /// - /// - public static string GetValue(string sectionsPath) - { - try - { - return Configuration[sectionsPath]; - } - catch (Exception) - { - } - return ""; + /// + /// 根据路径 configuration["App:Name"]; + /// + /// + /// + public static string GetValue(string sectionsPath) + { + try + { + return Configuration[sectionsPath]; + } + catch (Exception) + { } + + return ""; } } \ No newline at end of file diff --git a/Tiobon.Core.Common/Helper/Console/ConsoleHelper.cs b/Tiobon.Core.Common/Helper/Console/ConsoleHelper.cs index 1ce7d753..b2be8e9e 100644 --- a/Tiobon.Core.Common/Helper/Console/ConsoleHelper.cs +++ b/Tiobon.Core.Common/Helper/Console/ConsoleHelper.cs @@ -1,53 +1,50 @@ -using System; +namespace Tiobon.Core.Common; -namespace Tiobon.Core.Common +public static class ConsoleHelper { - public static class ConsoleHelper - { - private static readonly object _objLock = new(); + private static readonly object _objLock = new(); - /// - /// 在控制台输出 - /// - /// 文本 - /// 前颜色 - public static void WriteColorLine(string str, ConsoleColor color) + /// + /// 在控制台输出 + /// + /// 文本 + /// 前颜色 + public static void WriteColorLine(string str, ConsoleColor color) + { + lock (_objLock) { - lock (_objLock) - { - ConsoleColor currentForeColor = Console.ForegroundColor; - Console.ForegroundColor = color; - Console.WriteLine(str); - Console.ForegroundColor = currentForeColor; - } + ConsoleColor currentForeColor = Console.ForegroundColor; + Console.ForegroundColor = color; + Console.WriteLine(str); + Console.ForegroundColor = currentForeColor; } + } - /// - /// 打印错误信息 - /// - /// 待打印的字符串 - /// 想要打印的颜色 - public static void WriteErrorLine(this string str, ConsoleColor color = ConsoleColor.Red)=> WriteColorLine(str, color); + /// + /// 打印错误信息 + /// + /// 待打印的字符串 + /// 想要打印的颜色 + public static void WriteErrorLine(this string str, ConsoleColor color = ConsoleColor.Red)=> WriteColorLine(str, color); - /// - /// 打印警告信息 - /// - /// 待打印的字符串 - /// 想要打印的颜色 - public static void WriteWarningLine(this string str, ConsoleColor color = ConsoleColor.Yellow)=> WriteColorLine(str, color); + /// + /// 打印警告信息 + /// + /// 待打印的字符串 + /// 想要打印的颜色 + public static void WriteWarningLine(this string str, ConsoleColor color = ConsoleColor.Yellow)=> WriteColorLine(str, color); - /// - /// 打印正常信息 - /// - /// 待打印的字符串 - /// 想要打印的颜色 - public static void WriteInfoLine(this string str, ConsoleColor color = ConsoleColor.White)=> WriteColorLine(str, color); + /// + /// 打印正常信息 + /// + /// 待打印的字符串 + /// 想要打印的颜色 + public static void WriteInfoLine(this string str, ConsoleColor color = ConsoleColor.White)=> WriteColorLine(str, color); - /// - /// 打印成功的信息 - /// - /// 待打印的字符串 - /// 想要打印的颜色 - public static void WriteSuccessLine(this string str, ConsoleColor color = ConsoleColor.Green)=> WriteColorLine(str, color); - } + /// + /// 打印成功的信息 + /// + /// 待打印的字符串 + /// 想要打印的颜色 + public static void WriteSuccessLine(this string str, ConsoleColor color = ConsoleColor.Green)=> WriteColorLine(str, color); } diff --git a/Tiobon.Core.Model/HttpEnum.cs b/Tiobon.Core.Model/HttpEnum.cs index fcde8168..fc386293 100644 --- a/Tiobon.Core.Model/HttpEnum.cs +++ b/Tiobon.Core.Model/HttpEnum.cs @@ -1,10 +1,7 @@ -using System; +namespace Tiobon.Core.Model; -namespace Tiobon.Core.Model +public enum HttpEnum { - public enum HttpEnum - { - Common, - LocalHost - } + Common, + LocalHost } diff --git a/Tiobon.Core.Model/Love.cs b/Tiobon.Core.Model/Love.cs index 66972bca..497ce769 100644 --- a/Tiobon.Core.Model/Love.cs +++ b/Tiobon.Core.Model/Love.cs @@ -1,25 +1,24 @@ -namespace Tiobon.Core.Model +namespace Tiobon.Core.Model; + +/// +/// 这是爱 +/// +public class Love { - /// - /// 这是爱 - /// - public class Love + public virtual string SayLoveU() { - public virtual string SayLoveU() - { - return "I ♥ U"; - } - /// - /// id - /// - public int Id { get; set; } - /// - /// 姓名 - /// - public string Name { get; set; } - /// - /// 年龄 - /// - public int Age { get; set; } + return "I ♥ U"; } + /// + /// id + /// + public int Id { get; set; } + /// + /// 姓名 + /// + public string Name { get; set; } + /// + /// 年龄 + /// + public int Age { get; set; } } diff --git a/Tiobon.Core.Model/PageModel.cs b/Tiobon.Core.Model/PageModel.cs index 10b8c5e8..66f7bf3a 100644 --- a/Tiobon.Core.Model/PageModel.cs +++ b/Tiobon.Core.Model/PageModel.cs @@ -1,74 +1,72 @@ using AutoMapper; -namespace Tiobon.Core.Model +namespace Tiobon.Core.Model; + +/// +/// 通用分页信息类 +/// +public class PageModel { /// - /// 通用分页信息类 + /// 当前页标 /// - public class PageModel - { - /// - /// 当前页标 - /// - public int page { get; set; } = 1; - /// - /// 总页数 - /// - public int pageCount => (int)Math.Ceiling((decimal)dataCount / PageSize); - /// - /// 数据总数 - /// - public int dataCount { get; set; } = 0; - /// - /// 每页大小 - /// - public int PageSize { set; get; } = 20; - /// - /// 返回数据 - /// - public List data { get; set; } - - public PageModel() { } + public int page { get; set; } = 1; + /// + /// 总页数 + /// + public int pageCount => (int)Math.Ceiling((decimal)dataCount / PageSize); + /// + /// 数据总数 + /// + public int dataCount { get; set; } = 0; + /// + /// 每页大小 + /// + public int PageSize { set; get; } = 20; + /// + /// 返回数据 + /// + public List data { get; set; } - public PageModel(int page, int dataCount, int pageSize, List data) - { - this.page = page; - this.dataCount = dataCount; - PageSize = pageSize; - this.data = data; - } + public PageModel() { } - public PageModel ConvertTo() - { - return new PageModel(page, dataCount, PageSize, default); - } + public PageModel(int page, int dataCount, int pageSize, List data) + { + this.page = page; + this.dataCount = dataCount; + PageSize = pageSize; + this.data = data; + } + public PageModel ConvertTo() + { + return new PageModel(page, dataCount, PageSize, default); + } - public PageModel ConvertTo(IMapper mapper) - { - var model = ConvertTo(); - if (data != null) - { - model.data = mapper.Map>(data); - } + public PageModel ConvertTo(IMapper mapper) + { + var model = ConvertTo(); - return model; + if (data != null) + { + model.data = mapper.Map>(data); } + return model; + } - public PageModel ConvertTo(IMapper mapper, Action options) - { - var model = ConvertTo(); - if (data != null) - { - model.data = mapper.Map>(data, options); - } - - return model; + public PageModel ConvertTo(IMapper mapper, Action options) + { + var model = ConvertTo(); + if (data != null) + { + model.data = mapper.Map>(data, options); } + return model; + } }