# simple-tools **Repository Path**: sim-_-ple/simple-tools ## Basic Information - **Project Name**: simple-tools - **Description**: 通用的工具类的封装 - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2024-01-08 - **Last Updated**: 2025-06-20 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## 一个工具类,开发中使用可以帮助你提升效率 ### 测试用的实体 ```c sharp internal class Special :IParameterVerify { public Special() { this.Title = "xxx"; this.Age = 10; this.Pricef = 11.1f; this.Priced = 12.1; this.Pricede = 1213.11M; CreateTime = DateTime.Now; time = new TimeSpan(10,11,11); } [CusRequired("标题")] [ColName("title")] public string Title { get; set; } public int Age { get; set; } public float Pricef { get; set; } public double Priced { get; set; } public decimal Pricede { get; set; } public DateTime CreateTime{ get; set; } public TimeSpan time{ get; set; } public Dempartment dempartment { get; set; } } internal class Dempartment { public Dempartment() { } public string Title { get; set; } } ``` ### 验证穿的参数的属性是否合法 ```c sharp Special special = new Special(); var verify=special.Verify(); if (verify.Item2) { Console.WriteLine(verify.Item1); } ``` ### 可以将对象映射成字典集合(此过程可逆) ```c sharp special.dempartment = new Dempartment(); Special special2 = new Special(); Dictionary dic = special.MapToDictionary(); var s=special2.DictionaryToValue(dic); ``` ### http 快速使用 1.可以配置多个httpclient 2.通过设置defaultKey选择使用client发出请求 ```c sharp IHttpHelper httpHelper = new HttpHelper(); // 设置请求头 HttpHelper.AddHeard("token","value"); //多个客户端 通过key 找对应当的url HttpHelper.AddClient("api_v1","api"); httpHelper.Post("path",new { }).Then((resutl) => { //泛型方法可以指定类型,如果不指定就返回字符串 }); httpHelper.Get("path", new { }).Then((resutl) => { //泛型方法可以指定类型,如果不指定就返回字符串 }); httpHelper.Put("path", new { }).Then((resutl) => { //泛型方法可以指定类型,如果不指定就返回字符串 }); httpHelper.Delete("path").Then((resutl) => { //泛型方法可以指定类型,如果不指定就返回字符串 }); ``` ### 树型结构的简单封装 1.便于将列表转换为书结构 ``` c sharp //继承ITree接口 public class SimpleTree : ITree,IEquatable { public TKey ID { get { return key; } set { key = value; } } public TKey ParentID { get { return parentID; } set { parentID = value; } } public List Children { get { return children; } set { children = value; } } private TKey key; private TKey parentID; private List children; public virtual bool IsRoot(); public virtual bool Equals(TKey? other); ``` ### 产生雪花id ``` csharp IWorker worker = new Worker(); IWorker worker1 =Worker.Builder(); Console.WriteLine(worker.NextIdAsync().Result); Console.WriteLine(worker.NextId()); ```