NamespaceSystemLibrary.Common.Net.Extensions
This class contains extension methods for IEnumerables
IEnumerableExtensions
public static class IEnumerableExtensions
Inheritance
System.Object
IEnumerableExtensions
Methods
}
This class contains extension methods for IEnumerables
Select items grouped by a property of your choice
class Car
{
public string Name;
}
var car1 = new Car { Name = "Vehicle" }
var car2 = new Car { Name = "Vehicle" }
var list = new List<Car> { car1, car2 }
var list = list.DistinctBy(x => x.Name).ToList();
// list contains now 1 car
Name | Description |
---|---|
T | |
TKey |
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | items | |
System.Func<T, TKey> | selector |
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T> | IEnumerable filtered on the property of your choice |
Check if the IEnumerable contains 'value'
Does not throw on null
Uses Linq.Contains() internally, but does not throw on null
var texts = new string[] { "Hello", "World" };
var has = texts.Has("Abc");
//has is False
Name | Description |
---|---|
T |
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | enumerable | |
T | value |
Type | Description |
---|---|
System.Boolean | Returns true or false |
Check if the enumerable contains 'value', does not throw if value is null
Uses Linq.Contains() internally
var users = new List<User>();
var user = new User();
users.Add(user);
var result = users.Has(user);
// result is true, the list contains that specific user object
Name | Description |
---|---|
T |
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | enumerable | |
System.Object | value |
Type | Description |
---|---|
System.Boolean | Returns true or false |
Checks if the Enumerable exists and has at least 1 item
Does not throw exception on null
var list = new List<string>();
list.Add("hello world");
var result = list.Is();
// result is true as the list contains 1 item
List<string> list = null;
var result = list.Is();
// result is false as the list is null
Name | Description |
---|---|
T |
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | enumerable |
Type | Description |
---|---|
System.Boolean | True or false |
Checks if the Enumerable exists and has at least 1 item
Does not throw exception on null
var list = new List<string>();
var result = list.IsNot();
// result is true as the list contains 0 items
List<string> list = null;
var result = list.IsNot();
// result is true as the list currently is null
Name | Description |
---|---|
T |
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<T> | enumerable |
Type | Description |
---|---|
System.Boolean | True or false |
}