CleanEngine.Shared.Extension 3.0.1-beta

This is a prerelease version of CleanEngine.Shared.Extension.
There is a newer version of this package available.
See the version list below for details.
dotnet add package CleanEngine.Shared.Extension --version 3.0.1-beta
                    
NuGet\Install-Package CleanEngine.Shared.Extension -Version 3.0.1-beta
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CleanEngine.Shared.Extension" Version="3.0.1-beta" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CleanEngine.Shared.Extension" Version="3.0.1-beta" />
                    
Directory.Packages.props
<PackageReference Include="CleanEngine.Shared.Extension" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CleanEngine.Shared.Extension --version 3.0.1-beta
                    
#r "nuget: CleanEngine.Shared.Extension, 3.0.1-beta"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CleanEngine.Shared.Extension@3.0.1-beta
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CleanEngine.Shared.Extension&version=3.0.1-beta&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=CleanEngine.Shared.Extension&version=3.0.1-beta&prerelease
                    
Install as a Cake Tool

CleanEngine.Shared.Extension

CleanEngine.Shared.Extension is an extension for commonly used functions and rapid development.

Extension for value types convert methods

int integerNum = "123".ToInt32();//123
double longNum = "123.456".ToDouble();//123.456
decimal roundDecimal = 123.456m.ToRound(2);//123.46
double roundDouble = 123.456d.ToRound(2);//123.46

Extension for json convert

var json = new { Id = 1, Name = "Levi" }.ToJson();//{"Id":1,"Name":"Levi"}
var obj = "{\"Id\":1,\"Name\":\"Levi\"}".ToObject<Student>();
string result = "{\"name\":\"levi\", \"age\":18}".JsonAppendNode("person", new Person(Address: "shenzhen", Count: 100));

Extension for datetime convert

string now = DateTime.Now.ToStandardString();//2024-03-27 16:32:10

Extension for string

bool isEmpty = "".IsEmpty();//true
bool isNotEmpty = "".IsNotEmpty();//false
bool isEqual = "abc".EqualsIgnoreCase("ABC");//true
bool isNumber = "123".IsNumber();//true
bool isInteger = "123.12".IsInteger();//false
bool isDateTime = "2024-03-27".IsDateTime();//true

Extension for IEnumerable

var list = new List<string>() { "abc", "efg", "ggg" };
foreach (var item in list.WithIndex<string>())
{
	var index = item.Index;//get index from collection
	var value = item.Item;
 }
var isEmpty = list.IsNullOrEmpty();//false
var isNotEmpty = list.IsNotNullOrEmpty();//true

File Helper

FilesHelper.AppendOrCreate("x:\\xxx\\xxx.txt", text);//if file not exists, create; And then write text
FilesHelper.AppendOrCreate("x:\\xxx\\xxx.txt", new List<string>() { "123", "456" }););//if file not exists, create; And then write text

Validator Helper

var isIntegerPositive = ValidatorHelper.IsIntegerPositive("-100");//false
var isEnglish = ValidatorHelper.IsEnglishCharacter("abc");//true
var isEnglishAndInteger = ValidatorHelper.IsIntegerAndEnglishCharacter("abc123");//true

HttpClient Helper

One statement for HttpGet/HttpPost (Below version v1.3.0)

//with header
var html = new HttpEngine().GetString("https://www.baidu.com", x=>x.WithHeader("Accept-Language", "zh-CN"));

//with headers
var html2 = new HttpEngine().GetString("https://www.baidu.com", x => x.WithHeaders(new
            {
                Host = "www.baidu.com",
                Connection= "keep-alive"
            }));

//response convert to Object
var obj = new HttpEngine().Post<Employee>("http://192.168.1.1", x=>x.WithBearerToken("token"));

//response convert to List
List<Employee> list = new HttpEngine().PostList<Employee>("http://192.168.1.1");

(Below v3.0.0 and Equal / above version v1.3.0)

var html = new HttpEngineBuilder().Build().PostString("https://www.baidu.com");

var result = new HttpEngineBuilder().AddRequestBody(x => x.WithObject(new
{
    password = "password",
    userCode = "user"
})).Build().PostString("http://192.168.1.1:8888/api/login");

var html = _httpEngineBuilder.AddRequestHeader(x => x.WithHeaders(new
{
    Host = "www.baidu.com",
    Connection = "keep-alive"
})).Build().GetString("https://www.baidu.com");

var result = new HttpEngineBuilder().AddRequestBody(x => x.WithObject(new
{
    password = "password",
    userCode = "user"
})).Build().PostString<TestResponse>("http://192.168.1.1:8888/api/login");

(Equal and above version v3.0.0)

(v3.0.0版本及以上)

//.net framework
var html = new HttpBuilder().PostString("https://www.baidu.com");

var httpBuilder = new HttpBuilder();
var result = new HttpBuilder().AddRequestBody(x => x.WithObject(new
{
    password = "password",
    userCode = "user"
})).PostString("http://192.168.1.1:8888/api/login");

var html = new HttpBuilder().AddRequestHeader(x => x.WithHeaders(new
{
    Host = "www.baidu.com",
    Connection = "keep-alive"
})).GetString("https://www.baidu.com");

var result = new HttpBuilder().AddRequestBody(x => x.WithObject(new
{
    password = "password",
    userCode = "user"
})).PostString<TestResponse>("http://192.168.1.1:8888/api/login");

//.net core

//.net8 demo:
//register
builder.Services.AddHttpClient();
builder.Services.AddScoped<IHttpEngineAdapter, HttpEngineAdapter>();
builder.Services.AddScoped<IHttpBuilder, HttpBuilder>();

//add adapter class for use HttpClientFactory
    public class HttpEngineAdapter : IHttpEngineAdapter
    {
        private IHttpClientFactory _httpClientFactory;
        public HttpEngineAdapter(IHttpClientFactory httpClientFactory)
        {
            _httpClientFactory = httpClientFactory;
        }

        public HttpClient CreateHttpClient(string name = null, DelegatingHandler handler = null)
        {
            if (name == null)
                return _httpClientFactory.CreateClient();
            return _httpClientFactory.CreateClient(name);
        }
    }

//DI
    [ApiController]
    [Route("[controller]")]
    public class DebugController : ControllerBase
    {
        private IHttpBuilder _httpBuilder;

        public DebugController(IHttpBuilder httpBuilder)
        {
            _httpBuilder = httpBuilder;
        }
        [HttpPost("GetHtml")]
        public async Task<string> GetHtml()
        {
            return await _httpBuilder.AddRequestHeader(x => x.WithObject(new
                {
                    PageSize = 100,
                    PageNumber = 1,
                    Condition = "Product"
                })).GetStringAsync("https://www.example.com");

        }
        [HttpPost("login")]
        public async Task<IActionResult> login()
        {
            //request by header easily
            var result = await _httpBuilder
                //.AddClientHandler(x=>x.WithClientName("system"))
                .AddRequestHeader(x=>x.WithHeader("authorization", "Bearer HereIsYourBearerToken"))
                .GetStringAsync("https://www.example.com");
            return Ok(result);
        }
    }

(Equal and above version v3.0.1)

(v3.0.1版本及以上)

var httpBuilder = new HttpBuilder();
var result = httpBuilder.AddRequestHeader(x => x.WithHeaders(new
{
    Host = "www.baidu.com",
    Connection = "keep-alive"
})).GetString("https://www.baidu.com");
var afterClear = httpBuilder.Clear().GetString("https://www.baidu.com");//Clear all settings(Headers...) before request

Snowflake Id Generator

long id = IdGenerator.DefaultInstance().NextId();//163697223064879104 Generate a snowflake id
long distributedId = new IdGenerator(1,1).NextId();//163697287460163584 Generate a distibuted snowflake id with distibuted configuration

Reflection Helper

var dept = new Department() { Id = 1, Name = "it" };
string beforValue = ReflectionHelper.SetProperty<Department>(dept, "Name", "hr");//set property by key, value
  • v1.3.2 (1)增强FileHelper功能
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.3.2 141 6/19/2025
3.3.0 267 3/6/2025
3.2.1 226 3/6/2025
3.1.0 143 12/1/2024
3.0.2 149 10/27/2024
3.0.1-beta 125 9/23/2024
3.0.0-beta 113 9/14/2024
2.1.0-beta 101 9/14/2024
2.0.2 156 8/23/2024
2.0.1 124 7/23/2024
2.0.0 136 7/13/2024
1.3.2 141 7/6/2024
1.3.1 141 6/30/2024
1.3.0 130 6/29/2024
1.2.5 136 5/27/2024
1.2.4 142 4/15/2024
1.2.1 143 3/28/2024
1.2.0 149 3/27/2024
1.1.9 140 3/27/2024
1.1.7 147 3/23/2024
1.1.6 139 3/23/2024
1.1.5 149 3/23/2024
1.1.4 155 3/6/2024
1.1.3 147 2/29/2024
1.1.2 148 2/27/2024
1.1.1 131 2/27/2024