Пример #1
0
        private void ProcessInternal <T>(Func <object, T> converter)
        {
            var ds = DataSourceFactory.FromPSObjects(_data, converter);

            if (Dimensions != null)
            {
                ds.Reshape(Dimensions);
            }

            WriteObject(ds);
        }
Пример #2
0
        private void ProcessInternal <T>(Func <object, T> converter)
        {
            if (ParameterSetName == "load")
            {
                Path = IO.GetAbsolutePath(this, Path);
                var result = DataSourceFactory.Load <float>(Path, !NoDecompress);
                WriteObject(result);
            }
            else if (ParameterSetName == "rows")
            {
                var data = new List <T[]>();
                foreach (var row in Rows)
                {
                    var r = row.Select(x => {
                        if (x is PSObject)
                        {
                            x = (x as PSObject).BaseObject;
                        }

                        return(converter.Invoke(x));
                    });
                    data.Add(r.ToArray());
                }

                var result = DataSourceFactory.FromRows <T>(data, Dimensions);
                WriteObject(result);
            }
            else if (ParameterSetName == "columns")
            {
                var data = new List <T[]>();
                foreach (var column in Columns)
                {
                    var c = column.Select(x => {
                        if (x is PSObject)
                        {
                            x = (x as PSObject).BaseObject;
                        }

                        return(converter.Invoke(x));
                    });
                    data.Add(c.ToArray());
                }

                var result = DataSourceFactory.FromColumns(data, Dimensions);
                WriteObject(result);
            }
            else if (ParameterSetName == "psobjects")
            {
                var result = DataSourceFactory.FromPSObjects(PSObjects, converter);

                if (Dimensions != null)
                {
                    result.Reshape(Dimensions);
                }

                WriteObject(result);
            }
            else if (ParameterSetName == "datatable")
            {
                var result = DataSourceFactory.FromDataTable(DataTable, converter);

                if (Dimensions != null)
                {
                    result.Reshape(Dimensions);
                }

                WriteObject(result);
            }
            else
            {
                // new
                var result = DataSourceFactory.Create(Data.Select(x => converter.Invoke(x)).ToArray(), Dimensions);
                WriteObject(result);
            }
        }