/Extend

Extension methods for .Net

Primary LanguageC#MIT LicenseMIT

Welcome to Extend

Build Status

NuGet NuGet GitHub issues

License

What is this?

Extend is a set of .Net extension methods build as .NET Standard 1.1 library. Extend enhance the .Net framework by adding a bunch of methods to increase developer’s productivity. Currently it contains 417 unique extension methods (657 overloads included).

Where can I use it?

You can use it in every .Net application or library targeting one of the following profiles:

  • .NET Standard 1.1
  • .NET Core 1.1
  • .NET 4.5

See "Microsoft documentation" for a full list of all compatible frameworks.

How do I use it?

  1. Install "Extend" via NuGet Install-Package PortableExtensions
  2. Add using using Extend;
  3. Done!

Testing

To guarantee its stability Extend contains over 2400 unit tests. Each method has test with different input parameters, including invalid values to test the exception handling.

Example

Array to list using a selector:

var myArray = new[] {"1", "2", "3"};
var intValues = myArray.ToList(x => x.ToInt32());

Action executing based on boolean values:

var successful = SaveData();
successful.IfTrue(() => DisplaySuccess(), () => DisplayFailure());
successful.IfFalse(() => DisplayFailure(), () => DisplaySuccess());

Add to collection:

var list = new List<String>();
list.AddIf(x => new Random().Next(0, 10) % 2 == 0, "Value");
list.AddIfNotContains( "Value #1");
list.AddRange("Value #1", "Value #2", "Value #3");
list.AddRangeIfNotContains("Value #1", "Value #2", "Value #3");
list.AddRangeIf(x => new Random().Next(0, 10) % 2 == 0, "Value", "Value #2", "Value #3");

Working with dictionaries

var dictionary = new Dictionary<String, String>();
dictionary.AddOrUpdate("Key", "Value");
dictionary.AddRange(new Dictionary<String, String>
{
	{ "Key1", "Value1" },
	{ "Key2", "Value2" }
});
dictionary.GetOrAdd("Key", () => "Value");
var keyValueCsv = dictionary.StringJoin("=", ", ");

Working with IEnumerable:

var list = new List<String>();
var containsNotNullValues = list.AnyAndNotNull();
var distinctValues = list.Distinct(x => x.Substring(0, 2));
list.ForEach(x => { });
list.ForEachReverse(x => list.Remove(x));

Working with DateTime:

var dateTime = DateTime.Now;
var stringValue = dateTime.ToLongDateShortTimeString();
var elapsed = dateTime.Elapsed();
var isFuture = dateTime.IsFuture();
var weekend = dateTime.IsWeekendDay();

String templates:

"Today is the: {Today}".FormatWithObject( new { Today = DateTime.Now } );

"Today is the: {Today}".FormatWithObject( new Dictionary<String, Object> { { "Today", DateTime.Now } } );

License

Licensed under the MIT License.