public static bool IsNullOrEmpty<T>(this Collection<T> collection) { return collection == null || (collection != null && collection.Count() == 0); } |
Visualizzazione post con etichetta "extension method". Mostra tutti i post
Visualizzazione post con etichetta "extension method". Mostra tutti i post
martedì 23 luglio 2013
Testare se una collection è nulla o vuota (IsNullOrEmpty)
Metodo esteso che consente di testare se una collection è nulla o vuota (IsNullOrEmpty).
Etichette:
"c#",
"extension method"
martedì 18 giugno 2013
[WPF/SL/WP] Clonare ObservableCollection
Metodo esteso che consente di clonare una generica ObservableCollection.
public static ObservableCollection<T> Clone<T> (this ObservableCollection<T> source) { if (source != null) { var res = new ObservableCollection<T>(); foreach (var item in source) { res.Add(Clone<T>(item)); } return res; } return null; } |
lunedì 17 giugno 2013
Ottenere un sub-array da un array esistente
static T[] SubArray<T>(this T[] data, int index, int length) { T[] result = new T[length]; Array.Copy(data, index, result, 0, length); return result; }
Etichette:
"array",
"c#",
"extension method"
Iscriviti a:
Post (Atom)