Extend is a set of .Net extension methods build as portable class library. Extend enhance the .Net framework by adding a bunch of methods to increase developer’s productivity. Currently it contains 377 unique extension methods (623 overloads included).
You can use it in every .Net application or library targeting one of the following profiles:
- .Net 4.5
- Windows 8
- Windows Phone 8
- Windows Phone 8.1
- Install "Extend" via NuGet Install-Package PortableExtensions
- Add using for Extend
using Extend;
- Done!
To guarantee its stability Extend contains over 1900 unit tests. Each method has test with different input parameters, including invalid values to test the exception handling.
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();
Licensed under the MIT License.