public static IList TryConversion(this IList self, Type[] possibleTypes = null, bool raiseError = false) { possibleTypes = possibleTypes ?? DataMap.ConversionTypes; var type = GetDataType(self); ArgumentException cause = null; foreach (var t in possibleTypes) { if (t == type) { return(self); } try { return(SmartConverter.ConvertTo(t, self)); } catch (ArgumentException ex) { cause = ex; } } // If any possible types are not adequate, try to cast down the type of the first non-null element. return(CastDown(self)); }
public static PSObject Mode(PSObject self, bool skipNaN = true) { object array = self.BaseObject; // Convert values to double if they are not numeric var type = array.GetType().GetElementType(); if (!Utils.IsNumeric(type)) { array = SmartConverter.ConvertTo <double>((dynamic)array); } return(GenericIListExtensions.Mode((dynamic)array, skipNaN)); }
public static List <T> ToList <T>(this IList value) { if (value is IList <T> l) { return(new List <T>(l)); } var result = new List <T>(value.Count); for (var i = 0; i < value.Count; ++i) { result.Add(SmartConverter.ConvertTo <T>(value[i])); } return(result); }
public static T[] ToArray <T>(this IList value) { if (GetDataType(value) == typeof(T)) { ((IList <T>)value).ToArray(); } var result = new T[value.Count]; for (var i = 0; i < result.Length; ++i) { result[i] = SmartConverter.ConvertTo <T>(value[i]); } return(result); }
public override void Fit(SeriesBase data) { _encoding = new Dictionary <object, T>(); _categories = new List <object>(); var count = 0; foreach (var value in data.UnderlyingList) { if (!_encoding.ContainsKey(value)) { _encoding.Add(value, SmartConverter.ConvertTo <T>(count)); _categories.Add(value); ++count; } } }