SrkToolkit.Common
2.0.151
dotnet add package SrkToolkit.Common --version 2.0.151
NuGet\Install-Package SrkToolkit.Common -Version 2.0.151
<PackageReference Include="SrkToolkit.Common" Version="2.0.151" />
<PackageVersion Include="SrkToolkit.Common" Version="2.0.151" />
<PackageReference Include="SrkToolkit.Common" />
paket add SrkToolkit.Common --version 2.0.151
#r "nuget: SrkToolkit.Common, 2.0.151"
#:package SrkToolkit.Common@2.0.151
#addin nuget:?package=SrkToolkit.Common&version=2.0.151
#tool nuget:?package=SrkToolkit.Common&version=2.0.151
SrkToolit.Common
A lot of stuff is described as unit tests. It makes it obvious to see what the code does.
String extensions
AddHtmlLineBreaks
[TestMethod]
public void WorksWithWindowsLines()
{
string text = "aaa\r\nbbb\r\nccc";
string expected = "aaa<br />\r\nbbb<br />\r\nccc";
string actual = text.AddHtmlLineBreaks();
Assert.AreEqual(expected, actual);
}
Works with \r, \n and \r\n.
ToUpperFirstLetters
[TestMethod]
public void ManyWords()
{
string input = "hello wORLD";
string expected = "Hello WORLD";
string result = input.ToUpperFirstLetters();
Assert.AreEqual(expected, result);
}
CapitalizeWords
[TestMethod]
public void ManyWords_LeavesOtherCharsAsIs()
{
string input = "heLLo wORLd";
string expected = "Hello World";
string result = input.CapitalizeWords();
Assert.AreEqual(expected, result);
}
RemoveDiacritics
[TestMethod]
public void French()
{
string input = "Là bas se trouvent une çédille et un œuf. L'été fût dur. Par la fenêtre. En grève ex æquo.";
string expected = "La bas se trouvent une cedille et un oeuf. L'ete fut dur. Par la fenetre. En greve ex aequo.";
string result = input.RemoveDiacritics();
Assert.AreEqual(expected, result);
}
RemoveSpaces
[TestMethod]
public void SomeSpaces()
{
string input = " \t\n\r\u00A0\u2002\u2003\u2004\u2005\u205F";
string expected = "";
string result = input.RemoveSpaces();
Assert.AreEqual(expected, result);
}
MakeUrlFriendly
[TestMethod]
public void Test()
{
string input = "German uses the umlauts ä, ö and ü. ";
string expected = "german-uses-the-umlauts-a-o-and-u";
string result = input.MakeUrlFriendly(false);
Assert.AreEqual(expected, result);
}
[TestMethod]
public void PreserveCase()
{
string input = "German uses the umlauts ä, ö AND ü. ";
string expected = "German-uses-the-umlauts-a-o-AND-u";
string result = input.MakeUrlFriendly(true);
Assert.AreEqual(expected, result);
}
GetIncrementedString
[TestMethod]
public void Nothing()
{
string input = "test";
string expected = "test-1";
string result = input.GetIncrementedString();
Assert.AreEqual(expected, result);
}
[TestMethod]
public void After2Goes3()
{
string input = "test-2";
string expected = "test-3";
string result = input.GetIncrementedString();
Assert.AreEqual(expected, result);
}
You can pass a lambda as uniquenessCheck argument to check against a DB or something else.
many more...
NameValueCollection extensions
This old collection needs a few methods...
.ToDictionary() .AsEnumerable()
DateTime extensions
DateTime.UtcNow.ToPrecision(DateTimePrecision.Month)
DateTime.UtcNow.ToPrecision(DateTimePrecision.Minute)
var date1 = DateTime.UtcNow.ToPrecision(DateTimePrecision.Second)
date1.IsEqualTo(2, DateTimePrecision.Second)
var local = date1.AsLocal(); // changes the Kind to Local (does not convert)
var utc = local.AsUtc(); // changes the Kind to Utc (does not convert)
long unix = utc.ToUnixTime;
Array extensions
var a1 = new int[] { 0, 1, 2, };
var a2 = new int[] { 3, 4, };
var combined = a1.CombineWith(a2);
// 0, 1, 2, 3, 4
var combinedMore = a1.CombineWith(a2, combined, a1);
// 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2
ObservableCollection extensions
.AddRange()
.RemoveAll(x => x.Value == null)
Enum tools
EnumTool.GetDescription // gets a name from a resource dictionary
var desc = EnumTools.GetDescription(value, EnumStrings.ResourceManager);
var desc = EnumTools.GetDescription(value, EnumStrings.ResourceManager, null, "_Desc");
TimeZoneInfo extensions
ConvertToUtc & ConvertFromUtc
Converting DateTime to UTC is a little tricky with DateTime.Kind to handle. Calling a static method is not very friendly.
As I often convert to/from UTC, those 2 methods make it nicer.
// prepare
var date = new DateTime(1234, 5, 6, 7, 8, 9, 123, DateTimeKind.Utc);
var tz = TimeZoneInfo.FindSystemTimeZoneById("Romance Standard Time");
// before
TimeZoneInfo.ConvertTimeFromUtc(dateTime.AsUnspecified(), tz)
// after
var result = tz.ConvertFromUtc(tz, date);
// before
TimeZoneInfo.ConvertTimeToUtc(dateTime.AsUnspecified(), tz)
// after
result = tz.ConvertToUtc(tz, result);
DisposableOnce
Sometimes it is nice to use a using() { } block as an intuitive way to finaly{do-something}.
DisposableOnce allows you to create a disposable object that will call a delegate on dispose.
[TestMethod]
public void DelegateIsCalledOnceDispose()
{
// prepare
int disposed = 0;
var target = new DisposableOnce(() => disposed++);
// execute
target.Dispose();
// verify
Assert.AreEqual(1, disposed);
}
CultureInfoHelper.GetCountries()
Lists countries from the .NET cultures.
SrkToolkit.IO.RecursiveDelete
Multi-threaded recursive file delete.
SrkToolkit.Common.Validation.EmailAddress
Decomposes and composes an email address (account + tag + domain).
var emailSimple = new EmailAddress("someone.nice@sometest.com");
Assert.AreEqual(email.Account, "someone.nice");
Assert.AreEqual(email.Tag, null);
Assert.AreEqual(email.Domain, "sometest.com");
var emailTag = new EmailAddress("someone.nice+my-tag@sometest.com");
Assert.AreEqual(email.Account, "someone.nice");
Assert.AreEqual(email.Tag, "my-tag");
Assert.AreEqual(email.Domain, "sometest.com");
Assert.AreEqual(email.Value, "someone.nice+my-tag@sometest.com");
Assert.AreEqual(email.ValueWithoutTag, "someone.nice@sometest.com");
SrkToolkit.Common.Validation.PhoneNumber
Makes nicer phone numbers
"00123456", "0012 (0) 3456", "+12 34-56", "0012-34-56" => "+123456"
| 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 is compatible. 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 is compatible. 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. |
-
.NETFramework 4.8
- No dependencies.
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 4.4.1)
-
net8.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on SrkToolkit.Common:
| Package | Downloads |
|---|---|
|
SrkToolkit.Web.AspMvc5
SrkToolkit.Web.AspMvc5 is a bunch of extensions and components to use with your ASP MVC project. |
|
|
SrkToolkit.Web.AspNetCore2
SrkToolkit.Web.AspNetCore2 is a bunch of extensions and components to use with your ASP MVC Core project. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2.0.151 | 568 | 6/1/2026 |
| 2.0.150-preview1 | 88 | 6/1/2026 |
| 2.0.149-preview1 | 89 | 5/31/2026 |
| 2.0.148-preview2 | 660 | 8/16/2023 |
| 2.0.147-preview2 | 876 | 4/3/2023 |
| 2.0.146-preview1 | 277 | 3/27/2023 |
| 2.0.145-preview1 | 359 | 3/10/2023 |
| 2.0.144-preview1 | 347 | 3/10/2023 |
| 1.2.143 | 1,195 | 2/16/2023 |
| 1.2.141 | 820 | 2/3/2023 |
| 1.2.140 | 851 | 2/3/2023 |
| 1.2.139 | 1,313 | 5/9/2020 |
| 1.2.0-beta1 | 809 | 2/20/2019 |
| 1.1.136 | 2,150 | 12/7/2017 |
| 1.1.135 | 1,789 | 6/28/2017 |
| 1.1.134 | 1,823 | 2/2/2017 |
| 1.1.133 | 1,778 | 1/27/2017 |
| 1.1.133-pre | 1,239 | 9/15/2016 |
| 1.1.131 | 1,780 | 9/5/2016 |
Preview 2 of SrkToolkit v2. Not ready for production; use at your own risk.