public static string ToEngFormat <T, T2>(this System.Collections.Generic.IEnumerable <T> collection, string word, System.Func <T, T2> select, System.Func <T2, bool> where, System.Func <T2, string> select2) { System.Collections.Generic.List <string> list = new System.Collections.Generic.List <string>(); if (typeof(T).IsValueType) { using (System.Collections.Generic.IEnumerator <T> enumerator = collection.GetEnumerator()) { while (enumerator.MoveNext()) { T current = enumerator.Current; T2 arg = select(current); string item; if (where (arg) && !string.IsNullOrEmpty(item = select2(arg))) { list.Add(item); } } goto IL_CE; } } foreach (T current2 in collection) { T2 arg; string item; if (current2 != null && (arg = select(current2)) != null && where (arg) && !string.IsNullOrEmpty(item = select2(arg))) { list.Add(item); } } IL_CE: return(RCextensions.HandleEngFormat(word, list)); }
/// <summary> /// Counts the items within the given list. /// <locDE><para />Zählt die Elemente in der angegebenen Liste.</locDE> /// </summary> /// <typeparam name="T">The element type of the given list.<locDE><para />Elementtyp der angegebenen Liste.</locDE></typeparam> /// <param name="source">The list to count the contained items.<locDE><para />Liste, deren Elemente gezählt werden soll.</locDE></param> /// <param name="stopCountAt">Stop counting at this value (i.e. just want to know if there are at least n items). /// <locDE><para />Zählung beim Erreichen dieses Wertes abbrechen (wenn man nur wissen will, ob mind. soviele Elemente enthalten sind).</locDE></param> /// <returns>Item count (maybe limited by stopCountAt value).<locDE><para />Anzahl der Elemente (ggf. limitiert durch stopCountAt Wert).</locDE></returns> public static int Count <T>(this System.Collections.Generic.IEnumerable <T> source, int stopCountAt) { if (null == source) { return(0); } System.Collections.Generic.ICollection <T> genCollection = source as System.Collections.Generic.ICollection <T>; if (null != genCollection) { return(Math.Min(genCollection.Count, stopCountAt)); } System.Collections.ICollection stdcollection = source as System.Collections.ICollection; if (null != stdcollection) { return(Math.Min(stdcollection.Count, stopCountAt)); } int num = 0; using (System.Collections.Generic.IEnumerator <T> enumerator = source.GetEnumerator()) { while (enumerator.MoveNext()) { num++; if (num > stopCountAt) { break; } } } return(num); }
public static bool HasNewItem <T>(System.Collections.Generic.IEnumerable <T> list) where T : Csla.Core.BusinessBase { bool flag; using (System.Collections.Generic.IEnumerator <T> ienumerator = list.GetEnumerator()) { while (ienumerator.MoveNext()) { Csla.Core.BusinessBase businessBase = ienumerator.Current; if (businessBase.IsNew) { flag = true; return(flag); } } } return(false); }
/// <summary> /// Takes an IEnumerable-char input, and calls Append(...) on each character, appending a child element for each character to a root xml document. /// </summary> /// <param name="input"></param> public void Append(System.Collections.Generic.IEnumerable <char> input) { this.Append(input.GetEnumerator()); }
/// <summary>Compares the contents of a <see cref="System.Collections.Generic.IEnumerable{T}"/> /// implementation to another one to determine equality.</summary> /// <remarks>Thinking of the <see cref="System.Collections.Generic.IEnumerable{T}"/> implementation as /// a string with any number of characters, the algorithm checks /// each item in each list. If any item of the list is not equal (or /// one list contains all the elements of another list), then that list /// element is compared to the other list element to see which /// list is greater.</remarks> /// <param name="x">The <see cref="System.Collections.Generic.IEnumerable{T}"/> implementation /// that is considered the left hand side.</param> /// <param name="y">The <see cref="System.Collections.Generic.IEnumerable{T}"/> implementation /// that is considered the right hand side.</param> /// <returns>True if the items are equal, false otherwise.</returns> private static bool Equals(System.Collections.Generic.IEnumerable <T> x, System.Collections.Generic.IEnumerable <T> y) { // If x and y are null, then return true, they are the same. if (x == null && y == null) { // They are the same, return 0. return(true); } // If one is null, then return a value based on whether or not // one is null or not. if (x == null || y == null) { // Return false, one is null, the other is not. return(false); } // Check to see if the counts on the IEnumerable implementations are equal. // This is a shortcut, if they are not equal, then the lists are not equal. // If the result is indeterminate, then get out. bool?enumerableCountsEqual = EnumerableCountsEqual(x, y); // If the enumerable counts have been able to be calculated (indicated by // a non-null value) and it is false, then no need to iterate through the items. if (enumerableCountsEqual != null && !enumerableCountsEqual.Value) { // The sequences are not equal. return(false); } // The counts of the items in the enumerations are equal, or indeterminate // so a full iteration needs to be made to compare each item. // Get the default comparer for T first. System.Collections.Generic.EqualityComparer <T> defaultComparer = EqualityComparer <T> .Default; // Get the enumerator for y. System.Collections.Generic.IEnumerator <T> otherEnumerator = y.GetEnumerator(); // Call Dispose on IDisposable if there is an implementation on the // IEnumerator<T> returned by a call to y.GetEnumerator(). using (otherEnumerator as IDisposable) { // Cycle through the items in this list. foreach (T item in x) { // If there isn't an item to get, then this has more // items than that, they are not equal. if (!otherEnumerator.MoveNext()) { // Return false. return(false); } // Perform a comparison. Must check this on the left hand side // and that on the right hand side. bool comparison = defaultComparer.Equals(item, otherEnumerator.Current); // If the value is false, return false. if (!comparison) { // Return the value. return(comparison); } } // If there are no more items, then return true, the sequences // are equal. if (!otherEnumerator.MoveNext()) { // The sequences are equal. return(true); } // The other sequence has more items than this one, return // false, these are not equal. return(false); } }
/// <summary> /// Get an enumerator from the wrapped enumerable /// </summary> /// <returns>The enumerator (itself wrapped)</returns> public IEnumerator <T> GetEnumerator() { return(new GuardedEnumerator <T>(enumerable.GetEnumerator())); }