去除引用common.props

This commit is contained in:
2023-11-06 19:35:59 +08:00
parent 6a2154edd9
commit c6b8dfc861
810 changed files with 3910 additions and 6695 deletions

View File

@@ -1,6 +1,6 @@
using JNPF.DependencyInjection;
using System.Reflection;
using JNPF.DependencyInjection;
using Microsoft.Extensions.Caching.Memory;
using System.Reflection;
namespace JNPF.Common.Cache;

View File

@@ -226,7 +226,7 @@ public class RedisCache : ICache, ISingleton
}
public Task<string> GetHash(string key, string field)
{
return RedisHelper.HGetAsync(key, field);
return RedisHelper.HGetAsync(key, field);
}
public Task<bool> HashExist(string key, string field)
{
@@ -238,6 +238,6 @@ public class RedisCache : ICache, ISingleton
}
public Task<bool> HSet(string key, string field, string value)
{
return RedisHelper.HSetAsync(key, field,value);
return RedisHelper.HSetAsync(key, field, value);
}
}

View File

@@ -1,8 +1,8 @@
using JNPF.Common.Const;
using JNPF.Common.Manager;
using System.Runtime.InteropServices;
using JNPF.Common.Const;
using JNPF.Common.Extension;
using JNPF.Common.Manager;
using JNPF.DependencyInjection;
using System.Runtime.InteropServices;
using SkiaSharp;
namespace JNPF.Common.Captcha.General;

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JNPF.Common.Security;
using SqlSugar;
using SqlSugar;
namespace JNPF.Common.Contracts;
@@ -16,6 +10,6 @@ public class BaseEntity<TKey> : IEntity where TKey : IEquatable<TKey>
[SugarColumn(ColumnName = "id", ColumnDescription = "主键", IsPrimaryKey = true)]
public TKey id { get; set; }
}

View File

@@ -1,7 +1,6 @@
using JNPF.Common.Const;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using JNPF.Extras.DatabaseAccessor.SqlSugar.Models;
using SqlSugar;
namespace JNPF.Common.Contracts;

View File

@@ -1,7 +1,4 @@
using JetBrains.Annotations;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
namespace Tnb.Common;
@@ -159,11 +156,11 @@ public static class Check
short value,
string parameterName)
{
if(value == 0)
if (value == 0)
{
throw new ArgumentException($"{parameterName} is equal to zero");
}
else if(value < 0)
else if (value < 0)
{
throw new ArgumentException($"{parameterName} is less than zero");
}
@@ -251,7 +248,7 @@ public static class Check
Int16 minimumValue,
Int16 maximumValue = Int16.MaxValue)
{
if(value < minimumValue || value > maximumValue)
if (value < minimumValue || value > maximumValue)
{
throw new ArgumentException($"{parameterName} is out of range min: {minimumValue} - max: {maximumValue}");
}

View File

@@ -7,7 +7,7 @@ namespace JNPF.Common.Dtos.VisualDev;
/// 在线功能开发数据创建输入.
/// </summary>
[SuppressSniffer]
public class VisualDevModelDataCrInput: FlowTaskOtherModel
public class VisualDevModelDataCrInput : FlowTaskOtherModel
{
/// <summary>
/// 数据.

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.ComponentModel;
using System.ComponentModel;
using JNPF.DependencyInjection;
namespace JNPF.Common.Enums;

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.ComponentModel;
using System.ComponentModel;
using JNPF.DependencyInjection;
namespace JNPF.Common.Enums;

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.ComponentModel;
using System.ComponentModel;
using JNPF.DependencyInjection;
namespace JNPF.Common.Enums;

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.ComponentModel;
using System.ComponentModel;
using JNPF.DependencyInjection;
namespace JNPF.Common.Enums;

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.ComponentModel;
using System.ComponentModel;
using JNPF.DependencyInjection;
namespace JNPF.Common.Enums;

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.ComponentModel;
using System.ComponentModel;
using JNPF.DependencyInjection;
namespace JNPF.Common.Enums;

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.ComponentModel;
using System.ComponentModel;
using JNPF.DependencyInjection;
namespace JNPF.Common.Enums;

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.ComponentModel;
using System.ComponentModel;
using JNPF.DependencyInjection;
namespace JNPF.Common.Enums;

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.ComponentModel;
using System.ComponentModel;
using JNPF.DependencyInjection;
namespace JNPF.Common.Enums;

View File

@@ -22,7 +22,7 @@ public enum RequestType
/// POST请求.
/// </summary>
Run = 2,
/// <summary>
/// 本地方法
/// </summary>

View File

@@ -1,7 +1,7 @@
using JNPF.DependencyInjection;
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Dynamic;
using System.Reflection;
using JNPF.DependencyInjection;
using Newtonsoft.Json;
namespace JNPF.Common.Extension;

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration;
namespace Tnb.Common.Extension
{

View File

@@ -1,5 +1,4 @@
using System.Reflection;
using JNPF.DependencyInjection;
using JNPF.DependencyInjection;
namespace JNPF.Common.Extension;

View File

@@ -1,8 +1,8 @@
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.ComponentModel;
using System.Reflection;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
namespace JNPF.Common.Extension;

View File

@@ -1,8 +1,5 @@
using JNPF.DependencyInjection;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Text;
using JNPF.DependencyInjection;
namespace JNPF.Common.Extension;

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
using System.Linq.Expressions;
namespace JNPF.Common.Extension
{
@@ -55,7 +50,7 @@ namespace JNPF.Common.Extension
var castPropertyValue = Expression.Convert(propertyValue, property!.PropertyType);
var assignExp = Expression.Assign(propExp, castPropertyValue);
return Expression.Lambda<Action<T, object>>(assignExp, new[] { target,propertyValue }).Compile();
return Expression.Lambda<Action<T, object>>(assignExp, new[] { target, propertyValue }).Compile();
}
}

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.Text;
using System.Text;
using JNPF.DependencyInjection;
namespace JNPF.Common.Extension;

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.Text;
using System.Text;
using JNPF.DependencyInjection;
namespace JNPF.Common.Extension;

View File

@@ -1,11 +1,11 @@
using JNPF.Common.Security;
using JNPF.DependencyInjection;
using System.Diagnostics;
using System.Diagnostics;
using System.Globalization;
using System.Text.Json;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Web;
using JNPF.Common.Security;
using JNPF.DependencyInjection;
namespace JNPF.Common.Extension;

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.Common.Extension
namespace Tnb.Common.Extension
{
public static class TaskEx
{
@@ -25,7 +19,7 @@ namespace Tnb.Common.Extension
return tcs.Task;
}
public static async Task<T> Retry<T>(Func<Task<T>> task, int retries,
public static async Task<T> Retry<T>(Func<Task<T>> task, int retries,
TimeSpan delay, CancellationToken cts = default) =>
await task().ContinueWith(async innerTask =>
{
@@ -40,7 +34,7 @@ namespace Tnb.Common.Extension
public static async Task Catch(this Task task, Func<Exception,Task> exceptionHandler)
public static async Task Catch(this Task task, Func<Exception, Task> exceptionHandler)
{
try
{

View File

@@ -1,6 +1,5 @@
using System.Text.RegularExpressions;
using JNPF.Common.Extension;
using Microsoft.CodeAnalysis.CSharp.Syntax;
namespace System;
@@ -188,7 +187,7 @@ public static class StringExtensions
public static (string, string) LastSplit(this string str, char seperate)
{
int n = str.LastIndexOf(seperate);
if(n > 0)
if (n > 0)
{
return (str.Substring(0, n), str.Substring(n + 1));
}

View File

@@ -1,5 +1,5 @@
using JNPF.DependencyInjection;
using System.Drawing;
using System.Drawing;
using JNPF.DependencyInjection;
namespace JNPF.Common.Models.NPOI;

View File

@@ -1,6 +1,4 @@
using NPOI.SS.Formula.Functions;
namespace JNPF.Common.Models;
namespace JNPF.Common.Models;
/// <summary>
/// 通用登录配置-第三方登录配置.

View File

@@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace JNPF.Common.Net;
namespace JNPF.Common.Net;
public interface IUserAgent
{

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Options;
using Swashbuckle.AspNetCore.SwaggerUI;

View File

@@ -1,7 +1,4 @@
using Aspose.Cells;
using JNPF.Common.Enums;
using JNPF.ConfigurableOptions;
using NPOI.SS.Formula.Functions;
using JNPF.ConfigurableOptions;
namespace JNPF.Common.Options;

View File

@@ -1,5 +1,4 @@
using JNPF.Common.Enums;
using JNPF.ConfigurableOptions;
using JNPF.ConfigurableOptions;
namespace JNPF.Common.Options;

View File

@@ -1,6 +1,5 @@
using System.Text.RegularExpressions;
using JNPF.Common.Configuration;
using JNPF.Common.Extension;
using JNPF.Common.Models.NPOI;
using JNPF.DataEncryption;
using JNPF.DependencyInjection;

View File

@@ -1,8 +1,8 @@
using JNPF.DependencyInjection;
using System.Data;
using JNPF.DependencyInjection;
using NPOI.HSSF.UserModel;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using System.Data;
namespace JNPF.Common.Helper
{
@@ -10,7 +10,7 @@ namespace JNPF.Common.Helper
/// Excel导入操作类
/// 版 本V3.2.0
/// 版 权拓通智联科技有限公司http://www.tuotong-tech.com
/// 日 期2017.03.12.
/// 日 期2017.03.12.
/// </summary>
[SuppressSniffer]
public class ExcelImportHelper
@@ -108,7 +108,7 @@ namespace JNPF.Common.Helper
//}
//else
//{
dataRow[j] = cell.ToString()?.Trim();
dataRow[j] = cell.ToString()?.Trim();
//}
}
}
@@ -134,7 +134,7 @@ namespace JNPF.Common.Helper
sheet = null;
}
#region
for (int i = table.Rows.Count-1; i >= 0; i--)
for (int i = table.Rows.Count - 1; i >= 0; i--)
{
bool isnull = true;
for (int j = 0; j < table.Columns.Count; j++)

View File

@@ -1,11 +1,11 @@
using JNPF.Common.Configuration;
using JNPF.Common.Extension;
using JNPF.Common.Models;
using JNPF.DependencyInjection;
using System.Drawing;
using System.Drawing;
using System.Drawing.Imaging;
using System.Text;
using System.Web;
using JNPF.Common.Configuration;
using JNPF.Common.Extension;
using JNPF.Common.Models;
using JNPF.DependencyInjection;
namespace JNPF.Common.Security;

View File

@@ -1,7 +1,6 @@
using System.Net.NetworkInformation;
using System.Text;
using JNPF.DependencyInjection;
using JNPF.JsonSerialization;
using JNPF.RemoteRequest.Extensions;
using Microsoft.AspNetCore.Http;

View File

@@ -108,16 +108,16 @@ public class PinyinHelper
#region
/// <summary>
/// 汉字转换成全拼的拼音.
/// </summary>
/// <param name="Chstr"></param>
/// <returns></returns>
public static string Pinyin(string Chstr)
{
// 定义拼音区编码数组
int[] getValue = new int[]
/// <summary>
/// 汉字转换成全拼的拼音.
/// </summary>
/// <param name="Chstr"></param>
/// <returns></returns>
public static string Pinyin(string Chstr)
{
// 定义拼音区编码数组
int[] getValue = new int[]
{
-20319, -20317, -20304, -20295, -20292, -20283, -20265, -20257, -20242, -20230, -20051, -20036,
-20032, -20026, -20002, -19990, -19986, -19982, -19976, -19805, -19784, -19775, -19774, -19763,
-19756, -19751, -19746, -19741, -19739, -19728, -19725, -19715, -19540, -19531, -19525, -19515,
@@ -151,11 +151,11 @@ public class PinyinHelper
-11055, -11052, -11045, -11041, -11038, -11024, -11020, -11019, -11018, -11014, -10838, -10832,
-10815, -10800, -10790, -10780, -10764, -10587, -10544, -10533, -10519, -10331, -10329, -10328,
-10322, -10315, -10309, -10307, -10296, -10281, -10274, -10270, -10262, -10260, -10256, -10254
};
};
// 定义拼音数组
string[] getName = new string[]
{
// 定义拼音数组
string[] getName = new string[]
{
"A", "Ai", "An", "Ang", "Ao", "Ba", "Bai", "Ban", "Bang", "Bao", "Bei", "Ben",
"Beng", "Bi", "Bian", "Biao", "Bie", "Bin", "Bing", "Bo", "Bu", "Ba", "Cai", "Can",
"Cang", "Cao", "Ce", "Ceng", "Cha", "Chai", "Chan", "Chang", "Chao", "Che", "Chen", "Cheng",
@@ -189,7 +189,7 @@ public class PinyinHelper
"Za", "Zai", "Zan", "Zang", "Zao", "Ze", "Zei", "Zen", "Zeng", "Zha", "Zhai", "Zhan",
"Zhang", "Zhao", "Zhe", "Zhen", "Zheng", "Zhi", "Zhong", "Zhou", "Zhu", "Zhua", "Zhuai", "Zhuan",
"Zhuang", "Zhui", "Zhun", "Zhuo", "Zi", "Zong", "Zou", "Zu", "Zuan", "Zui", "Zun", "Zuo"
};
};
// 验证是否输入汉字
Regex reg = new Regex("^[\u4e00-\u9fa5]$");

View File

@@ -1,6 +1,6 @@
using JNPF.DependencyInjection;
using System.Data;
using System.Data;
using System.Reflection;
using JNPF.DependencyInjection;
namespace JNPF.Common.Security;

View File

@@ -1,7 +1,5 @@
using System.Runtime.InteropServices;
using JNPF.Common.Cache;
using JNPF.Common.Const;
using JNPF.FriendlyException;
using Yitter.IdGenerator;
namespace JNPF.Common.Security;
@@ -11,56 +9,56 @@ namespace JNPF.Common.Security;
/// </summary>
public class SnowflakeIdHelper
{
// 定义dll路径
public const string RegWorkerId_DLL_NAME = "lib\\regworkerid_lib_v1.3.1\\yitidgengo.dll";
// 定义dll路径
public const string RegWorkerId_DLL_NAME = "lib\\regworkerid_lib_v1.3.1\\yitidgengo.dll";
// 根据文档定义三个接口
// 根据文档定义三个接口
// 注册一个 WorkerId会先注销所有本机已注册的记录
// ip: redis 服务器地址
// port: redis 端口
// password: redis 访问密码,可为空字符串“”
// maxWorkerId: 最大 WorkerId
[DllImport(RegWorkerId_DLL_NAME, EntryPoint = "RegisterOne", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false)]
private static extern ushort RegisterOne(string ip, int port, string password, int maxWorkerId);
// 注册一个 WorkerId会先注销所有本机已注册的记录
// ip: redis 服务器地址
// port: redis 端口
// password: redis 访问密码,可为空字符串“”
// maxWorkerId: 最大 WorkerId
[DllImport(RegWorkerId_DLL_NAME, EntryPoint = "RegisterOne", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false)]
private static extern ushort RegisterOne(string ip, int port, string password, int maxWorkerId);
// 注销本机已注册的 WorkerId
[DllImport(RegWorkerId_DLL_NAME, EntryPoint = "UnRegister", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false)]
private static extern void UnRegister();
// 注销本机已注册的 WorkerId
[DllImport(RegWorkerId_DLL_NAME, EntryPoint = "UnRegister", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false)]
private static extern void UnRegister();
// 检查本地WorkerId是否有效0-有效,其它-无效)
[DllImport(RegWorkerId_DLL_NAME, EntryPoint = "Validate", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false)]
private static extern int Validate(int workerId);
// 检查本地WorkerId是否有效0-有效,其它-无效)
[DllImport(RegWorkerId_DLL_NAME, EntryPoint = "Validate", CallingConvention = CallingConvention.Cdecl, ExactSpelling = false)]
private static extern int Validate(int workerId);
/// <summary>
/// 初始化YitId配置
/// </summary>
public static void InitYitIdWorker()
{
//var option = new IdGeneratorOptions
//{
// WorkerId = 1, //必须 全局唯一,必须 程序设定,理论最大值 2^WorkerIdBitLength-1
// //BaseTime = new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc), //用生成ID时的系统时间与基础时间的差值(毫秒数)作为生成ID的时间戳
// WorkerIdBitLength = 16, //机器码位长,决定 WorkerId 的最大值,默认值6,取值范围 [1, 16]
// //SeqBitLength = 4, //序列数位长,默认值6,取值范围 [3, 21](建议不小于4),决定每毫秒基础生成的ID个数
// //MinSeqNumber = 5, //最小序列数,默认值5,取值范围 [5, MaxSeqNumber]
// //MaxSeqNumber 最大序列数,设置范围 [MinSeqNumber, 2^SeqBitLength-1]默认值0
//};
var option = App.GetConfig<IdGeneratorOptions>("YitId");
if (option.WorkerId == 0)
/// <summary>
/// 初始化YitId配置
/// </summary>
public static void InitYitIdWorker()
{
CacheOptions _cacheOptions = App.GetConfig<CacheOptions>("Cache", true);
option.WorkerId = RegisterOne(_cacheOptions.ip, _cacheOptions.port, _cacheOptions.password, 63);
//var option = new IdGeneratorOptions
//{
// WorkerId = 1, //必须 全局唯一,必须 程序设定,理论最大值 2^WorkerIdBitLength-1
// //BaseTime = new DateTime(2023, 1, 1, 0, 0, 0, DateTimeKind.Utc), //用生成ID时的系统时间与基础时间的差值(毫秒数)作为生成ID的时间戳
// WorkerIdBitLength = 16, //机器码位长,决定 WorkerId 的最大值,默认值6,取值范围 [1, 16]
// //SeqBitLength = 4, //序列数位长,默认值6,取值范围 [3, 21](建议不小于4),决定每毫秒基础生成的ID个数
// //MinSeqNumber = 5, //最小序列数,默认值5,取值范围 [5, MaxSeqNumber]
// //MaxSeqNumber 最大序列数,设置范围 [MinSeqNumber, 2^SeqBitLength-1]默认值0
//};
var option = App.GetConfig<IdGeneratorOptions>("YitId");
if (option.WorkerId == 0)
{
CacheOptions _cacheOptions = App.GetConfig<CacheOptions>("Cache", true);
option.WorkerId = RegisterOne(_cacheOptions.ip, _cacheOptions.port, _cacheOptions.password, 63);
}
YitIdHelper.SetIdGenerator(option);
}
YitIdHelper.SetIdGenerator(option);
}
/// <summary>
/// 生成ID.
/// </summary>
/// <returns></returns>
public static string NextId()
{
return YitIdHelper.NextId().ToString();
}
/// <summary>
/// 生成ID.
/// </summary>
/// <returns></returns>
public static string NextId()
{
return YitIdHelper.NextId().ToString();
}
}

View File

@@ -8,17 +8,17 @@ namespace Tnb.Common.Utils
{
return objectType == typeof(DateTime);
}
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
{
TypeCode typeCode = Type.GetTypeCode(reader.Value.GetType());
if (typeCode == TypeCode.DateTime)
return reader.Value;
var t = long.Parse((string)(reader.Value.ToString()));
return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(t);
}
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
{
throw new NotImplementedException();

View File

@@ -1,10 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Linq.Expressions;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.Common.Utils
{

View File

@@ -1,12 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JNPF.Common.Contracts;
using NPOI.SS.Formula.Functions;
namespace Tnb.Common.Utils
namespace Tnb.Common.Utils
{
/// <summary>
/// 迪杰斯特拉(最短路径算法)

View File

@@ -1,13 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Reflection;
using System.Security.Policy;
using System.Net.Http.Headers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using JNPF.Logging;
using Microsoft.AspNetCore.WebUtilities;
using Newtonsoft.Json;
@@ -130,7 +122,7 @@ namespace Tnb.Common.Utils
}
public static async Task<string> PostStreamAsync(string url,object content, CancellationToken cancellationToken)
public static async Task<string> PostStreamAsync(string url, object content, CancellationToken cancellationToken)
{
using (var client = new HttpClient())
using (var request = new HttpRequestMessage(HttpMethod.Post, url))

View File

@@ -1,11 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.Common.Utils
namespace Tnb.Common.Utils
{
public class PropertyNotNullChecker<T>
{

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tnb.Common.Utils
namespace Tnb.Common.Utils
{
[AttributeUsage(AttributeTargets.Method)]
public class SkipNormalizationAttribute : Attribute

View File

@@ -1,13 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using JNPF.SpecificationDocument;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Tnb.Common.Utils
namespace Tnb.Common.Utils
{
//public class SkipNormalizationAttributeConventionalRegistrar : IConventionalRegistrar
//{

View File

@@ -5,133 +5,133 @@ namespace System;
public static class ThrowIf
{
public static void When(bool isMatch, string msg)
{
if (isMatch)
public static void When(bool isMatch, string msg)
{
throw new ArgumentException(msg);
}
}
public static T IsNull<T>([NotNull] T? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
{
if (value == null)
{
throw string.IsNullOrEmpty(msg) ? new ArgumentNullException(paraName) : new ArgumentException(msg);
if (isMatch)
{
throw new ArgumentException(msg);
}
}
return value;
}
public static T IsNullOrDefault<T>([NotNull] T? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null) where T : struct
{
if (!value.HasValue || value.Value.Equals(default(T)))
public static T IsNull<T>([NotNull] T? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
{
throw string.IsNullOrEmpty(msg) ? new ArgumentException("值不可为空或默认值", paraName) : new ArgumentException(msg);
if (value == null)
{
throw string.IsNullOrEmpty(msg) ? new ArgumentNullException(paraName) : new ArgumentException(msg);
}
return value;
}
return value.Value;
}
public static string IsNullOrWhiteSpace([NotNull] string? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
{
if (string.IsNullOrWhiteSpace(value))
public static T IsNullOrDefault<T>([NotNull] T? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null) where T : struct
{
throw string.IsNullOrEmpty(msg) ? new ArgumentException("值不可为空或空格", paraName) : new ArgumentException(msg);
}
return value;
}
if (!value.HasValue || value.Value.Equals(default(T)))
{
throw string.IsNullOrEmpty(msg) ? new ArgumentException("值不可为空或默认值", paraName) : new ArgumentException(msg);
}
public static string IsNullOrEmpty([NotNull] string? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
{
if (string.IsNullOrEmpty(value))
{
throw string.IsNullOrEmpty(msg) ? new ArgumentException("值不可为空", paraName) : new ArgumentException(msg);
return value.Value;
}
return value;
}
//public static ICollection<T> NotNullOrEmpty<T>(ICollection<T> value, string paraName)
//{
// if (value.IsNullOrEmpty())
// {
// throw new ArgumentException(paraName + " can not be null or empty!", paraName);
// }
// return value;
//}
//public static Type AssignableTo<TBaseType>(Type type, string paraName)
//{
// NotNull(type, paraName);
// if (!type.IsAssignableTo<TBaseType>())
// {
// throw new ArgumentException(paraName + " (type of " + type.AssemblyQualifiedName + ") should be assignable to the " + typeof(TBaseType).GetFullNameWithAssemblyName() + "!");
// }
// return type;
//}
public static short OutOfRange(short value, string paraName, short minimumValue, short maximumValue = short.MaxValue)
{
if (value < minimumValue || value > maximumValue)
public static string IsNullOrWhiteSpace([NotNull] string? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
if (string.IsNullOrWhiteSpace(value))
{
throw string.IsNullOrEmpty(msg) ? new ArgumentException("值不可为空或空格", paraName) : new ArgumentException(msg);
}
return value;
}
return value;
}
public static int OutOfRange(int value, string paraName, int minimumValue, int maximumValue = int.MaxValue)
{
if (value < minimumValue || value > maximumValue)
public static string IsNullOrEmpty([NotNull] string? value, string? msg = null, [CallerArgumentExpression("value")] string? paraName = null)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
if (string.IsNullOrEmpty(value))
{
throw string.IsNullOrEmpty(msg) ? new ArgumentException("值不可为空", paraName) : new ArgumentException(msg);
}
return value;
}
return value;
}
//public static ICollection<T> NotNullOrEmpty<T>(ICollection<T> value, string paraName)
//{
// if (value.IsNullOrEmpty())
// {
// throw new ArgumentException(paraName + " can not be null or empty!", paraName);
// }
public static long OutOfRange(long value, string paraName, long minimumValue, long maximumValue = long.MaxValue)
{
if (value < minimumValue || value > maximumValue)
// return value;
//}
//public static Type AssignableTo<TBaseType>(Type type, string paraName)
//{
// NotNull(type, paraName);
// if (!type.IsAssignableTo<TBaseType>())
// {
// throw new ArgumentException(paraName + " (type of " + type.AssemblyQualifiedName + ") should be assignable to the " + typeof(TBaseType).GetFullNameWithAssemblyName() + "!");
// }
// return type;
//}
public static short OutOfRange(short value, string paraName, short minimumValue, short maximumValue = short.MaxValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
if (value < minimumValue || value > maximumValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
}
return value;
}
return value;
}
public static float OutOfRange(float value, string paraName, float minimumValue, float maximumValue = float.MaxValue)
{
if (value < minimumValue || value > maximumValue)
public static int OutOfRange(int value, string paraName, int minimumValue, int maximumValue = int.MaxValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
if (value < minimumValue || value > maximumValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
}
return value;
}
return value;
}
public static double OutOfRange(double value, string paraName, double minimumValue, double maximumValue = double.MaxValue)
{
if (value < minimumValue || value > maximumValue)
public static long OutOfRange(long value, string paraName, long minimumValue, long maximumValue = long.MaxValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
if (value < minimumValue || value > maximumValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
}
return value;
}
return value;
}
public static decimal OutOfRange(decimal value, string paraName, decimal minimumValue, decimal maximumValue = decimal.MaxValue)
{
if (value < minimumValue || value > maximumValue)
public static float OutOfRange(float value, string paraName, float minimumValue, float maximumValue = float.MaxValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
if (value < minimumValue || value > maximumValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
}
return value;
}
return value;
}
public static double OutOfRange(double value, string paraName, double minimumValue, double maximumValue = double.MaxValue)
{
if (value < minimumValue || value > maximumValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
}
return value;
}
public static decimal OutOfRange(decimal value, string paraName, decimal minimumValue, decimal maximumValue = decimal.MaxValue)
{
if (value < minimumValue || value > maximumValue)
{
throw new ArgumentException($"{paraName} is out of range min: {minimumValue} - max: {maximumValue}");
}
return value;
}
}