RedCorners 4.1.1
See the version list below for details.
dotnet add package RedCorners --version 4.1.1
NuGet\Install-Package RedCorners -Version 4.1.1
<PackageReference Include="RedCorners" Version="4.1.1" />
paket add RedCorners --version 4.1.1
#r "nuget: RedCorners, 4.1.1"
// Install RedCorners as a Cake Addin
#addin nuget:?package=RedCorners&version=4.1.1
// Install RedCorners as a Cake Tool
#tool nuget:?package=RedCorners&version=4.1.1
RedCorners
RedCorners brings some neat utilities to your C# projects.
For more documentation, visit https://github.com/saeedafshari/RedCorners
Extensions
RedCorners offers a number of extension methods to boost productivity. All extensions are under the RedCorners
namespace:
using RedCorners;
String Manipulation
string string.Head(int take = 20)
This method returns the first take=20
characters of a non-null string. If the original input has less of equal to take
characters, the original string is returned, otherwise the output contains the first take
characters from the input, followed by ...
, making it a take+3
characters output.
In case the input is null
, an empty string is returned.
Examples:
Console.WriteLine($"Hello, World! This is a very long text.".Head());
Console.WriteLine($"Hello, World! This is a very long text.".Head(100));
// Hello, World! This i...
// Hello, World! This is a very long text.
HashSet<string> string.Hashtags()
This method takes a string as an input, and returns a HashSet<string>
containing the hashtags mentioned in the input. If the input is null
, an empty HashSet<string>
is returned.
Hashtags are converted to LowerInvariant forms.
Example:
string input = "Hello #World #EVERYBODY!";
var hashtags = input.Hashtags();
Console.WriteLine($"Hashtags: {string.Join(" ", hashtags)}");
// Hashtags: #world #everybody
string string.RemoveDuplicateTags(...)
string.RemoveDuplicateTags(bool humanFormatted = false, string separator = ",")
This method takes a separator
separated input containing tags, removes duplicate tags, trims tags and converts them to lowercase, and returns a new string with the result. If humanFormatted
is true
, the output tags will have a space between them. Example:
Console.WriteLine("food, Drinks, FooD,fun".RemoveDuplicateTags());
Console.WriteLine("food, Drinks, FooD,fun".RemoveDuplicateTags(true));
// food,drinks,fun
// food, drinks, fun
string string.RemovePrefix(string prefix)
This method returns a string without the specified prefix
. If the input is null
, null
is returned. Examples:
Console.WriteLine("Hello, World!".RemovePrefix("Hello"));
Console.WriteLine("Hello, World!".RemovePrefix("Foo"));
// , World!
// Hello, World!
bool string.IsValidEmail()
This method returns true
if the input is a valid email address. It relies on System.Net.Mail.MailAddress
. Example:
Assert("foo@hotmail.com");
Assert(!"not an email address");
I/O Extensions
string string.CreateDirectoryAndReturn()
This method takes a path as its input, creates that path if it doesn't exist, and returns the input. It is useful when chained with other I/O actions. Example:
this.FilePath = Path
.Combine(basePath, "ObjectStorage", bucket, typeFileName)
.CreateDirectoryAndReturn();
Date/Time Extensions
DateTime long.DateFromEpochMs()
This method returns a UTC DateTime equivalent to the input long
in milliseconds. Example:
long epoch = 1557738320000;
Console.WriteLine(epoch.DateFromEpochMs());
// 5/13/2019 9:05:20 AM
long DateTime.ToEpochMs()
This method is the opposite of long.DateFromEpochMs()
, where it converts a DateTime
to epoch milliseconds, as long
.
int DateTime.ToWeekNumber()
This method returns the week number for the input DateTime
, relative to 2019-03-11
.
DateTime int.GetFirstDayOfWeek()
This method returns the DateTime for the first day of the input week number. Example:
DateTime input = DateTime.UtcNow;
Console.WriteLine(input);
int weekNumber = input.ToWeekNumber();
Console.WriteLine(weekNumber);
Console.WriteLine(weekNumber.GetFirstDayOfWeek());
weekNumber++;
Console.WriteLine(weekNumber.GetFirstDayOfWeek());
// 5/13/2019 9:20:15 AM
// 9
// 5/13/2019 12:00:00 AM
// 5/20/2019 12:00:00 AM
DateTime int.GetLastDayOfWeek()
This method returns the DateTime for the first day of the next week. Identical to:
(weeknumber + 1).GetFirstDayOfWeek();
Injection Extensions
RedCorners provides extensions that facilitate converting data where models have different base classes, but share some properties.
void Inject(object destination)
This method looks at the properties of the destination
object, and where there is an identical property in the source, it copies the value of the source to that property of the destination. Example:
class Contact
{
public int Id { get; set; }
public int Name { get; set; }
public int Email { get; set; }
}
class UpdateContactModel
{
public int Name { get; set; }
public int Email { get; set; }
}
...
Contact original = new Contact {
Id = 10,
Name = "John",
Email = "john@redcorners.com"
};
UpdateContactModel update = new UpdateContactModel {
Name = "Sarah",
Email = "sarah@redcorners.com"
};
// Inject Name and Email from [update] to [original]
update.Inject(original);
Console.WriteLine(original.Id);
// Prints [10], because UpdateContactModel doesn't have a property named [Id]
Console.WriteLine(original.Name);
// Prints [Sarah], because it was injected from the UpdateContactModel
T object.ReturnAs<T>() where T : new()
This method injects an object to a new object of type T
and returns the new T
. Example:
Contact contact = update.ReturnAs<Contact>();
Console.WriteLine(original.Id);
// Prints [0], because UpdateContactModel doesn't have a property named [Id], so the default(int) is used.
Console.WriteLine(original.Name);
// Prints [Sarah], because it was injected from the UpdateContactModel
List<T> IEnumerable<object>.ReturnAsList<T>() : where T : new()
This method returns a list of objects of type T
from an arbitrary list of objects of any type, by doing one-by-one Inject
s.
Components
Components are under the RedCorners.Components
namespace.
Benchmark
RedCorners.Components.Benchmark
is using a Stopwatch
to time some actions. Example:
Benchmark benchmark = new Benchmark();
await Task.Delay(1234);
Console.WriteLine(benchmark.ToString());
await Task.Delay(4321);
Console.WriteLine(benchmark.StopToString());
// 1.24s
// 5.57s
TimeSpan Benchmark.Stop()
Stops the timer and returns the duration as a TimeSpan
.
string Benchmark.ToString()
Returns the duration as a string with two decimal points and the s
prefix. Does not stop the timer, and can be used multiple times.
string Benchmark.StopToString()
Same as ToString()
, but stops the timer.
ObjectStorage<T> where T : class, new()
This class helps with storage of serializable objects of type T
as JSON files. The storage path is defined by the static
property DefaultBasePath
and by default, it is set to:
public static Func<string> DefaultBasePath = () => Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
This component is currently experimental and more information will be published on it in later updates.
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. |
.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
- Newtonsoft.Json (>= 12.0.1)
NuGet packages (6)
Showing the top 5 NuGet packages that depend on RedCorners:
Package | Downloads |
---|---|
RedCorners.Forms
Side Bar, Tabbed View and more for your Xamarin.Forms projects. |
|
RedCorners.Forms.GoogleMaps
Advanced Google Maps for Xamarin Forms (iOS and Android). |
|
RedCorners.Components.ObjectStorage
Easy cross-platform storage of settings as JSON in C#. |
|
POIWorld.Client
Client for POIWorld and Wikidata |
|
RedCorners.ApiClient
API Client for RedCorners Backends. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
18.0.0 | 452 | 12/4/2022 |
17.0.0 | 401 | 12/4/2022 |
16.0.0 | 289 | 12/4/2022 |
15.0.0 | 296 | 12/4/2022 |
14.0.0 | 3,826 | 5/29/2022 |
13.0.0 | 1,553 | 5/27/2022 |
12.0.0 | 419 | 5/22/2022 |
11.0.0 | 420 | 5/7/2022 |
10.0.0 | 406 | 5/6/2022 |
9.0.1 | 433 | 4/11/2022 |
9.0.0 | 407 | 4/11/2022 |
8.0.0 | 28,762 | 2/26/2020 |
7.0.0 | 773 | 1/28/2020 |
6.0.0 | 4,501 | 12/18/2019 |
5.0.0 | 10,972 | 7/7/2019 |
4.11.0 | 1,912 | 6/20/2019 |
4.10.0 | 1,409 | 6/18/2019 |
4.1.4 | 714 | 6/17/2019 |
4.1.3 | 510 | 6/17/2019 |
4.1.2 | 4,007 | 5/17/2019 |
4.1.1 | 2,386 | 5/13/2019 |
4.0.0 | 4,065 | 3/17/2019 |
RedCorners brings some neat utilities to your C# projects.