Exemple #1
0
        private IList <T> TryCast <T>(int index, IList list)
        {
            var result = list as IList <T>;

            if (result == null)
            {
                var t = GenericIListExtensions.GetDataType(list);
                throw new ArgumentException($"Column {index} type mismatch: expected type is {typeof(T).Name}, but actual type is {t.Name}");
            }
            return(result);
        }
Exemple #2
0
        public void TestSortBy()
        {
            var s  = new [] { 1, 2, 3, 4 };
            var by = new [] { 4, 3, 1, 2 };

            var t = GenericIListExtensions.SortBy(s, by);

            Assert.Equal(new[] { 3, 4, 2, 1 }, t);

            GenericIListExtensions.SortByFill(s, by);

            Assert.Equal(new[] { 3, 4, 2, 1 }, s);
        }
Exemple #3
0
        public void TestGetDataType()
        {
            var t1 = GenericIListExtensions.GetDataType(new int[0]);

            Assert.Equal(typeof(int), t1);

            var t2 = GenericIListExtensions.GetDataType(new List <double>());

            Assert.Equal(typeof(double), t2);

            var t3 = GenericIListExtensions.GetDataType(new ArrayList());

            Assert.Equal(typeof(object), t3);
        }
Exemple #4
0
        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));
        }