weihanli / weihanli.common Goto Github PK
View Code? Open in Web Editor NEWcommon tools, methods, extension methods, etc... .net 常用工具类,公共方法,常用扩展方法等,基础类库
Home Page: https://weihanli.github.io/WeihanLi.Common/index.html
License: Apache License 2.0
common tools, methods, extension methods, etc... .net 常用工具类,公共方法,常用扩展方法等,基础类库
Home Page: https://weihanli.github.io/WeihanLi.Common/index.html
License: Apache License 2.0
There are many warnings for AOT, let's fix them
https://devblogs.microsoft.com/dotnet/creating-aot-compatible-libraries/
Create this issue for tracking the nullable reference types.
Now all projects had enabled nullable reference types, but some API may not as expected, create issue for tracking these API
Built-in ioc support
dependency injection
SqlBulkCopy支持设置 BulkCopyTimeout
For example:
var result = TemplateEngine.CreateDefault().RenderAsync("Hello {{$env USERNAME}}");
Console.WriteLine(result);
API changes:
public interface ITemplateRenderer
{
- Task<string> RenderAsync(TemplateRenderContext template, object globals);
+ Task<string> RenderAsync(TemplateRenderContext template, object? globals = null);
}
Add ContextAccessor
to easily use context like IHttpContextAccessor
Introduce ReadOnlyRepository
for query only
Update SecurityHelper.Random
for a thread safe one
PropertyGetter
和 PropertySetter
以及内部缓存Add .NET 8.0 target support
net8.0
target for Commonnet6.0
for extensions
Castle
extensionsSerilog
extensionsrefact HttpRequester
with HttpClient
Add ValueTask
support for PipelineBuilder
Implement a JSON data builder for Nested JSON support
Add CancellationToken
support for CommandExecutor.ExecuteAsync
/CommandExecutor.ExecuteAndCaptureAsync
ExecuteCommandAndCapture
/ExecuteCommandAndCaptureAsync
for returning CommandResult
ConsoleHelper.PrintOutput
extension for CommandResult
EnsureSuccessfulExitCode
to EnsureSuccessExitCode
likes HttpResponseMessage.EnsureSuccessStatusCode()
这里应该用 outStream.ToArray not outStream.GetBuffer
IEventBase
, maybe we could remove the constraint to make it much easier to use.https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md
数据库MSSQL Server,
使用的查询语句:select ArmId as Id,ArmName as Name from arm
位置:
WeihanLi.Common/Helpers/SecurityHelper.cs
使用两种表达式验证
IsSafeSqlString 方法都是返回false,
该方法不能用于执行sql语句前判断注入吗?
Add ITenantIdProvider
likes IUserIdProvider
for example:
Hello {{name|upper}}
Hello {{ date | date:"yyyy-MM-dd" }}
Hello {{ name | replace:"123":"Abc" | upper }}
大佬 weihanli.npoi 咋不更新了
add AOP abstracts and implement for AspectCore
and Castle
support one-method aes encrypt/decrypt in SecurityHelper
Simple command line parser to parse the command line input and avoid issue:
dotnet/command-line-api#1385
Possible implement:
class CommandLineParer
{
public static IEnumerable<string> SplitCommandLine(string commandLine)
{
var memory = commandLine.AsMemory();
var startTokenIndex = 0;
var pos = 0;
var seeking = Boundary.TokenStart;
var seekingQuote = Boundary.QuoteStart;
while (pos < memory.Length)
{
var c = memory.Span[pos];
if (char.IsWhiteSpace(c))
{
if (seekingQuote == Boundary.QuoteStart)
{
switch (seeking)
{
case Boundary.WordEnd:
yield return CurrentToken();
startTokenIndex = pos;
seeking = Boundary.TokenStart;
break;
case Boundary.TokenStart:
startTokenIndex = pos;
break;
}
}
}
else if (c == '\"')
{
if (seeking == Boundary.TokenStart)
{
switch (seekingQuote)
{
case Boundary.QuoteEnd:
yield return CurrentToken();
startTokenIndex = pos;
seekingQuote = Boundary.QuoteStart;
break;
case Boundary.QuoteStart:
startTokenIndex = pos + 1;
seekingQuote = Boundary.QuoteEnd;
break;
}
}
else
{
switch (seekingQuote)
{
case Boundary.QuoteEnd:
seekingQuote = Boundary.QuoteStart;
break;
case Boundary.QuoteStart:
seekingQuote = Boundary.QuoteEnd;
break;
}
}
}
else if (seeking == Boundary.TokenStart && seekingQuote == Boundary.QuoteStart)
{
seeking = Boundary.WordEnd;
startTokenIndex = pos;
}
Advance();
if (IsAtEndOfInput())
{
switch (seeking)
{
case Boundary.TokenStart:
break;
default:
yield return CurrentToken();
break;
}
}
}
void Advance() => pos++;
string CurrentToken()
{
return memory.Slice(startTokenIndex, IndexOfEndOfToken()).ToString().Trim('"');
}
int IndexOfEndOfToken() => pos - startTokenIndex;
bool IsAtEndOfInput() => pos == memory.Length;
}
private enum Boundary
{
TokenStart,
WordEnd,
QuoteStart,
QuoteEnd
}
}
查询多条数据的时候先转了datatable,然后才转的 Entity
抽象 DataReader
数据到 Entity 的转换,支持更多数据类型,如简单类型 int/long/string,甚至更为复杂的对象如 Dictionary 等,并去掉 TEntity new()
限制,可以参考 dapper 实现
Ado.Net 默认的超时时间是 30s,有一些比较复杂或者数据量较大的查询可能会超过30s,需要提供一个参数支持手动设置 timeout 以方便调用
add logging filter so we can specific the logs we do not wanna record
**.NET information
Version: 7.0.0
FrameworkDescription: .NET 7.0.0
Libraries version: 7.0.0
Libraries hash: d099f075e45d2aa6007a22b71b45a08758559f80
**Environment information
ProcessorCount: 12
OSArchitecture: X64
OSDescription: Microsoft Windows 10.0.19044
OSVersion: Microsoft Windows NT 10.0.19044.0
Currently, we only support one field orderBy, while in some scenes, we may need to order by multi fields.
Add the following methods to IRepository interface:
int Update(TEntity entity, params Expression<Func<TEntity, object>>[] propertyExpressions);
int Update(TEntity entity, params string[] propertyNames);
Task UpdateAsync(TEntity entity, Expression<Func<TEntity, object>>[] propertyExpressions, CancellationToken cancellationToken = default);
Task UpdateAsync(TEntity entity, string[] propertyNames, CancellationToken cancellationToken = default);
Purpose:
Make application service layer depend the IRepository instead of the IEFRepository layer so it decouples the domain service and the infrusture.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.