Mastronardi.Utils.Extensions 1.0.0

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Mastronardi.Utils.Extensions --version 1.0.0                
NuGet\Install-Package Mastronardi.Utils.Extensions -Version 1.0.0                
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="Mastronardi.Utils.Extensions" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mastronardi.Utils.Extensions --version 1.0.0                
#r "nuget: Mastronardi.Utils.Extensions, 1.0.0"                
#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.
// Install Mastronardi.Utils.Extensions as a Cake Addin
#addin nuget:?package=Mastronardi.Utils.Extensions&version=1.0.0

// Install Mastronardi.Utils.Extensions as a Cake Tool
#tool nuget:?package=Mastronardi.Utils.Extensions&version=1.0.0                

Extension Utils

DateTime

To get the start of your week use this method:

var firstDayOfWeek = date.StartOfWeek(DayOfWeek.Monday);

when you do this you get the first monday of the week of the date you provide

Enum Extensions

The functionality of these extensions are coming from Mastronardi.Utils.Enums and are provided here as extension methods.

public static string GetDescription(this System.Enum value)

public static string GetDescription(this FieldInfo field)

public static Dictionary<string, string> GetListItems(this Type enumType)

public static Dictionary<int, string> GetIntegerListItems(this Type enumType)

public static Dictionary<char, string> GetCharacterListItems(this Type enumType)

It will get you the System.ComponentModel.DescriptionAttribute text if available, either as a string, or a list when you get the entire enum's values

Image extensions

Resizing an image in one easy step:

public static Image ResizeImage(this Image image, Size size, bool preserveAspectRatio = true)

It allows you to maintain aspect ratio and just resizes the image, after this you can choose what you do with it. It's still in memory.

Number extensions

public static Int32 RoundUp(this Int32 num, Int32 multiple)

public static decimal RoundUp(this decimal num, decimal multiple)

You can round up or down, as explained in Mastronardi.Utils.CustomMath

String extensions

Serialisation to json is nice, it can serialize to camelcase or snake case, but what if you need to convert a string representation of that property yourself? well:

string camelCase = "MyPropertyName".ToCamelCase();

this will result in camelCase being "myPropertyName";

string snake_case = "MyPropertyName".ToCamelCase();

this will result in snake_case being "my_property _name";

the next one is very difficult:

string result = "<h1>value</h1>".StripHTML();

It strips the html and will result to "value". Very usefull when you want to just plainly strip ALL Html

But what about replacing words, and sometimes case insensitive?

string result = "this is My text".ReplaceWholeWord("my","some",RegexOptions.IgnoreCase);

This will result in "this is some text". You can use all other RegexOptions too

string output = string1.StripNonAlphaNumeric();

This will strip all characters that are not numbers or letters... it basically cleans your string of those characters.

And then this one:

static public string[] SplitOnAnyNonNumber(this string input)

It splits a string on any non number... returning an array of numbers (as string, as they might contain leading zeros) What can you use it for? I don't even remember what I used it for, but if its usefull, let me know of your use case 😃:

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 is compatible.  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 is compatible. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 is compatible.  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 (2)

Showing the top 2 NuGet packages that depend on Mastronardi.Utils.Extensions:

Package Downloads
Mastronardi.Utils.Web

The Web utils help working with HTML, cleaning HTML, Parsing it, Parsing CSS, Embedding images, Querystring handling

Mastronardi.Utils.JQuery

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.7 526 10/10/2022
1.0.0 241 8/28/2023