/// <summary> /// Accepts a list of objects and converts them to a strongly typed list. /// </summary> /// <remarks>This should be put into a utility class as it's not directly /// related to data access.</remarks> public static IList <T> ConvertToList <T>(this System.Collections.IEnumerable objects) { if (objects == null) { return(new List <T>()); } return(objects.Cast <T>().ToList()); }
/// <summary> /// From a Source collection of items having a property, which is also another collection, gets the union of all the items of these collections. /// </summary> public static System.Collections.IEnumerable SelectMany(System.Collections.IEnumerable Source, string CollectionTechName) { var Collections = Source.Cast <object>() .Select(item => Get(item, CollectionTechName) as System.Collections.IEnumerable); foreach (var Collection in Collections) { foreach (var Item in Collection) { yield return(Item); } } }
public static List <float> ToFloatList(object obj) { List <float> aResult = new List <float>(); if (obj != null) { System.Collections.IEnumerable aValues = obj as System.Collections.IEnumerable; if (aValues != null) { aResult = aValues.Cast <float>().ToList(); } } return(aResult); }
public static List <double> ToDoubleList(object obj) { List <float> aResult = new List <float>(); if (obj != null) { System.Collections.IEnumerable aValues = obj as System.Collections.IEnumerable; if (aValues != null) { aResult = aValues.Cast <float>().ToList(); } } List <double> results = aResult.ConvertAll(x => (double)x).ToList(); return(results); }
/// <summary> /// Implicit or Explicit Converts the items of the specified enumerable. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="enumerable">The enumerable.</param> /// <param name="explicit">if set to <c>true</c> [explicit].</param> /// <returns></returns> public static IEnumerable <T> ConvertEach <T>(this System.Collections.IEnumerable enumerable, bool @explicit = false) { return(enumerable.Cast <object>().Select(it => InvokeConvert(it, typeof(T), @explicit)).Cast <T>()); }
protected ExpressionSyntax EmitCreateArray(Type elementType, System.Collections.IEnumerable values) { return(DefaultViewCompilerCodeEmitter.EmitCreateArray(UseType(elementType), values.Cast <object>().Select(EmitValue))); }
public static double Norm(this System.Collections.IEnumerable value, Func <object, Double> func) { Contract.Requires <ArgumentNullException>(value != null); Contract.Requires <ArgumentNullException>(func != null); return(value.Cast <object>().Norm(func)); }
protected void define_enum(string name, SC.IEnumerable values) { _curProcessDef.DataTypes.AddType(new EnumDef { Name = name, EnumValues = new List <string>(values.Cast <string>()) }); }
public void AddRange(System.Collections.IEnumerable elements) { this.AddRange(elements.Cast <Element>()); }