T1.Standard
1.0.85
dotnet add package T1.Standard --version 1.0.85
NuGet\Install-Package T1.Standard -Version 1.0.85
<PackageReference Include="T1.Standard" Version="1.0.85" />
paket add T1.Standard --version 1.0.85
#r "nuget: T1.Standard, 1.0.85"
// Install T1.Standard as a Cake Addin #addin nuget:?package=T1.Standard&version=1.0.85 // Install T1.Standard as a Cake Tool #tool nuget:?package=T1.Standard&version=1.0.85
Release Notes: https://mr-brain.github.io/categories/t1-standard/
T1.Standard.IO
StringTemplate
This class provides a simple way to create string templates with placeholders that can be replaced with values. It is useful for generating dynamic strings with variable content. Here's an example of how to use it:
var st = new StringTemplate("Hello @name");
st.SetAttribute("name", "mr.brain");
var text = st.ToString();
Assert.Equal("Hello mr.brain", text);
T1.Standard.Net
HttpClientEventStream
This is an asynchronous method for handling an event stream, specifically code for interacting with an AI or chat API. Here's a detailed explanation:
HttpClient client;
var client = new HttpClientEventStream(client, jsonSerializer);
var lines = client.PostEventStreamAsync("messageStream", req);
await foreach (var line in lines)
{
if (line.StartsWith(": ping"))
{
continue;
}
var token = jsonSerializer.Deserialize<GptToken>(line);
yield return token;
if (token is { IsEnd: true })
{
break;
}
}
T1.Standard.DesignPatterns
Either<TLeft, TRight>
The Either pattern can help address the performance issues associated with throwing exceptions. Exceptions should be reserved for scenarios where a problem is truly irrecoverable for the user or when the application cannot handle the situation. They are not meant to be used as a catch-all mechanism for every kind of error, only to be caught and handled externally.
Instead, Either provides a structured way to represent and handle both success and failure outcomes, making the code more predictable and efficient.
Here’s the demonstrating how to use the Either<TLeft, TRight> class to handle situations where a method might return one of two results (a left value or a right value). This example simulates handling a response from an API.
// Simulate a synchronous operation
Either<string, int> PerformOperation(bool isSuccess)
{
if (isSuccess)
{
return new Either<string, int>(42); // Return right value on success
}
return new Either<string, int>("An error occurred."); // Return left value on failure
}
// Handle the result (synchronous version)
void HandleResult(Either<string, int> result)
{
result.Switch(
left => Console.WriteLine($"Operation failed with error: {left}"),
right => Console.WriteLine($"Operation succeeded with result: {right}")
);
}
// Simulate an asynchronous operation
async Task<Either<string, int>> PerformOperationAsync(bool isSuccess)
{
await Task.Delay(500); // Simulate delay
return PerformOperation(isSuccess);
}
// Handle the result (asynchronous version)
Task HandleResultAsync(Either<string, int> result)
{
return result.SwitchAsync(
async left =>
{
Console.WriteLine($"Async operation failed with error: {left}");
await Task.CompletedTask;
},
async right =>
{
Console.WriteLine($"Async operation succeeded with result: {right}");
await Task.CompletedTask;
}
);
}
T1.Standard.Common
MethodCache
Using this method, you can easily add caching functionality to any method:
public class YourService
{
private readonly MethodCache _cache;
public YourService()
{
_cache = new MethodCache(defaultCacheDuration: TimeSpan.FromMinutes(5));
}
public async Task<UserInfo> GetUserInfoAsync(string userId)
{
// Original Implementation…
}
public Task<UserInfo> GetUserInfoWithCacheAsync(string userId)
{
return _cache.WithCacheAsync(
() => GetUserInfoAsync(userId),
cacheKey: $"GetUserInfoAsync:{userId}"
);
}
}
The advantages of this implementation include:
- Highly reusable - MethodCache can be used with any class and method.
- Flexibility - Different cache expiration times can be specified for each method call.
- Type-safe - Generics ensure type safety.
- Simplicity - No need to create specific wrapper methods for every method that needs caching.
T1.Standard.Data.SqlBuilders
MssqlBuilder
Generate Insert T-SQL statement string
var sqlBuilder = new MssqlBuilder();
var tableInfo = sqlBuilder.GetTableInfo(typeof(CustomerEntity));
var sqlCode = sqlBuilder.CreateInsertStatement(tableInfo);
T1.Standard.Collections.TreeBuilder
ReduceTree
Universal way to convert List of items to Tree, Build the tree as completely as possible
var userList = new[]
{
new MyUser { Path = "", Name = "A1" },
new MyUser { Path = "", Name = "A2" },
new MyUser { Path = "demo", Name = "B1" }
};
var actual = _treeBuilder.ReduceTree(userList,
x => x.Path,
x => _treeBuilder.GetParentPath(x),
x => _treeBuilder.QueryParentPaths(x.Path)
).ToList();
var expected = new List<TreeBuilder.TreeItem<MyUser, string>>
{
new TreeBuilder.TreeItem<MyUser, string>()
{
Id = "",
ParentId = null,
Item = new MyUser {Path = "", Name = "A1"},
Children = new List<TreeBuilder.TreeItem<MyUser, string>>()
},
new TreeBuilder.TreeItem<MyUser, string>()
{
Id = "",
ParentId = null,
Item = new MyUser {Path = "", Name = "A2"},
Children = new List<TreeBuilder.TreeItem<MyUser, string>>()
},
new TreeBuilder.TreeItem<MyUser, string>()
{
Id = "demo",
ParentId = null,
Item = new MyUser {Path = "demo", Name = "B1"},
Children = new List<TreeBuilder.TreeItem<MyUser, string>>()
},
};
expected.ToExpectedObject().ShouldEqual(actual);
GenerateTree
This will only create a fully structured tree
var userList = new[]
{
new MyUser {Path = "", Name = "A1"},
new MyUser {Path = "demo/name", Name = "C1"},
};
var actual = _treeBuilder.GenerateTree(userList,
x => x.Path,
x => _treeBuilder.GetParentPath(x.Path)
).ToList();
var expected = new List<TreeBuilder.TreeItem<MyUser, string>>
{
new TreeBuilder.TreeItem<MyUser, string>()
{
Id = "",
ParentId = null,
Item = new MyUser {Path = "", Name = "A1"},
Children = new List<TreeBuilder.TreeItem<MyUser, string>>()
},
};
expected.ToExpectedObject().ShouldEqual(actual);
string/object Dictionary List to DataTable Sample
var dictList = new List<Dictionary<string, object>> {
new Dictionary<string, object>
{
{"Id", 1},
{"Name", "Jack"},
{"Birth", DateTime.Parse("2022-05-01")}
},
new Dictionary<string, object>
{
{"Id", 2},
{"Name", "Flash"},
{"Birth", DateTime.Parse("2022-05-01")}
}
};
var datatable = dictList.ToDataTable();
string/object Dictionary List Deep to DataTable Sample
var dictList = new List<Dictionary<string, object>> {
new Dictionary<string, object>
{
{"Id", 1},
{"Name", "Jack"},
{"Birth", DateTime.Parse("2022-05-01")},
{"Price", null},
},
new Dictionary<string, object>
{
{"Id", 2},
{"Name", "Flash"},
{"Birth", DateTime.Parse("2022-05-01")},
{"Price", 123m},
{"Home", null},
}
};
var datatable = dictList.DeepToDataTable();
Assert.Equal(typeof(decimal), dt.Columns["Price"]!.DataType);
Assert.Equal(typeof(string), dt.Columns["Home"]!.DataType);
Product | Versions 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. |
.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. |
-
.NETStandard 2.0
- Castle.Core (>= 4.3.1)
- Microsoft.CSharp (>= 4.5.0)
- Microsoft.Extensions.Caching.Memory (>= 2.1.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 3.1.4)
- Microsoft.Extensions.Http (>= 2.1.1)
- Microsoft.Extensions.Localization.Abstractions (>= 1.1.0)
- Microsoft.Extensions.Logging (>= 2.1.1)
- Microsoft.Extensions.Primitives (>= 2.1.1)
- System.ComponentModel (>= 4.3.0)
- System.ComponentModel.Annotations (>= 4.5.0)
- System.Reactive (>= 4.1.5)
- System.Reactive.Core (>= 4.1.5)
- System.Reactive.Interfaces (>= 4.1.5)
- System.Reactive.Linq (>= 4.1.5)
- System.Reactive.Providers (>= 4.1.5)
- System.Runtime.Loader (>= 4.3.0)
- System.Text.Json (>= 4.7.2)
NuGet packages (10)
Showing the top 5 NuGet packages that depend on T1.Standard:
Package | Downloads |
---|---|
FlashElf.ChaosKit.Autofac
Package Description |
|
T1.AspNetCore3
DynamicHub, DefaultRequestResponseLoggingHandler, RawHtmlInjectMiddleware, ProtectFolderMiddleware |
|
FlashElf.ChaosKit
Chaos strategy is a software development strategy based on the chaos model. Its main rule is to always solve the most important problems first. |
|
T1.RedisEx
Package Description |
|
T1.SqlLocalData
windows sqllocaldb tool |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.85 | 28 | 1/29/2025 |
1.0.84 | 87 | 12/2/2024 |
1.0.83 | 223 | 11/16/2024 |
1.0.81 | 225 | 8/31/2024 |
1.0.80 | 148 | 8/19/2024 |
1.0.79 | 140 | 8/18/2024 |
1.0.78 | 145 | 6/2/2024 |
1.0.74 | 308 | 4/9/2023 |
1.0.67 | 610 | 2/8/2023 |
1.0.66 | 535 | 8/8/2022 |
1.0.65 | 530 | 6/27/2022 |
1.0.63 | 502 | 6/1/2022 |
1.0.62 | 498 | 5/4/2022 |
1.0.61 | 809 | 4/26/2022 |
1.0.59 | 479 | 4/21/2022 |
1.0.58 | 10,182 | 2/15/2022 |
1.0.57 | 594 | 6/30/2021 |
1.0.54 | 5,690 | 1/17/2021 |
1.0.53 | 704 | 1/12/2021 |
1.0.52 | 1,516 | 12/29/2020 |
1.0.50 | 3,967 | 12/9/2020 |
1.0.49 | 886 | 12/8/2020 |
1.0.45 | 1,193 | 11/18/2020 |
1.0.44 | 470 | 11/15/2020 |
1.0.42 | 528 | 9/3/2020 |
1.0.40 | 575 | 9/2/2020 |
1.0.38 | 4,631 | 9/1/2020 |
1.0.37 | 763 | 8/29/2020 |
1.0.36 | 532 | 8/26/2020 |
1.0.35 | 3,836 | 8/20/2020 |
1.0.33 | 536 | 7/29/2020 |
1.0.32 | 944 | 7/14/2020 |
1.0.31 | 622 | 6/19/2020 |
1.0.30 | 1,322 | 4/29/2020 |
1.0.29 | 569 | 4/5/2020 |
1.0.28 | 562 | 3/30/2020 |
1.0.26 | 557 | 3/27/2020 |
1.0.25 | 521 | 3/20/2020 |
1.0.24 | 875 | 1/31/2020 |
1.0.23 | 677 | 10/31/2019 |
1.0.22 | 586 | 10/12/2019 |
1.0.19 | 746 | 10/8/2019 |
1.0.18 | 551 | 10/5/2019 |
1.0.17 | 736 | 9/28/2019 |
1.0.16 | 578 | 9/11/2019 |
1.0.15 | 589 | 9/8/2019 |
1.0.14 | 644 | 8/22/2019 |
1.0.10 | 608 | 8/18/2019 |
add HttpClientEventStream