SrkToolkit.Common
2.0.147-preview2
See the version list below for details.
dotnet add package SrkToolkit.Common --version 2.0.147-preview2
NuGet\Install-Package SrkToolkit.Common -Version 2.0.147-preview2
<PackageReference Include="SrkToolkit.Common" Version="2.0.147-preview2" />
paket add SrkToolkit.Common --version 2.0.147-preview2
#r "nuget: SrkToolkit.Common, 2.0.147-preview2"
// Install SrkToolkit.Common as a Cake Addin #addin nuget:?package=SrkToolkit.Common&version=2.0.147-preview2&prerelease // Install SrkToolkit.Common as a Cake Tool #tool nuget:?package=SrkToolkit.Common&version=2.0.147-preview2&prerelease
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 is compatible. 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. |
.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 | net40 is compatible. net403 was computed. net45 was computed. net451 was computed. net452 was computed. net46 was computed. 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. |
-
.NETFramework 4.0
- No dependencies.
-
.NETStandard 2.0
- System.ComponentModel.Annotations (>= 4.4.1)
-
net7.0
- System.ComponentModel.Annotations (>= 4.4.1)
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.148-preview2 | 379 | 8/16/2023 |
2.0.147-preview2 | 686 | 4/3/2023 |
2.0.146-preview1 | 127 | 3/27/2023 |
2.0.145-preview1 | 150 | 3/10/2023 |
2.0.144-preview1 | 127 | 3/10/2023 |
1.2.143 | 598 | 2/16/2023 |
1.2.141 | 280 | 2/3/2023 |
1.2.140 | 293 | 2/3/2023 |
1.2.139 | 687 | 5/9/2020 |
1.2.0-beta1 | 579 | 2/20/2019 |
1.1.136 | 1,190 | 12/7/2017 |
1.1.135 | 1,010 | 6/28/2017 |
1.1.134 | 1,020 | 2/2/2017 |
1.1.133 | 981 | 1/27/2017 |
1.1.133-pre | 837 | 9/15/2016 |
1.1.131 | 996 | 9/5/2016 |
1.1.130 | 980 | 9/3/2016 |
1.1.129 | 1,091 | 1/26/2016 |
1.1.127 | 1,104 | 11/17/2015 |
1.1.126 | 1,060 | 11/15/2015 |
1.1.125 | 1,081 | 5/9/2015 |
Preview 1 of SrkToolkit v2. Not ready for production; use at your own risk.