/// <summary>
        /// Returns the getters for all columns.
        /// </summary>
        public static Delegate[] GetAllGetters(DataViewRowCursor cur)
        {
            var sch = cur.Schema;
            var res = new List <Delegate>();

            for (int i = 0; i < sch.Count; ++i)
            {
                if (sch[i].IsHidden)
                {
                    continue;
                }
                var getter = GetColumnGetter(cur, SchemaHelper._dc(i, cur), sch);
                if (getter == null)
                {
                    throw Contracts.Except($"Unable to get getter for column {i} from schema\n{SchemaHelper.ToString(sch)}.");
                }
                res.Add(getter);
            }
            return(res.ToArray());
        }
        public static Delegate GetGetterChoice <T1, T2, T3>(DataViewRowCursor cur, DataViewSchema.Column col)
        {
            Delegate res = null;

            try
            {
                res = cur.GetGetter <T1>(col);
                if (res != null)
                {
                    return(res);
                }
            }
            catch (Exception)
            {
            }
            try
            {
                res = cur.GetGetter <T2>(col);
                if (res != null)
                {
                    return(res);
                }
            }
            catch (Exception)
            {
            }
            try
            {
                res = cur.GetGetter <T3>(col);
                if (res != null)
                {
                    return(res);
                }
            }
            catch (Exception)
            {
            }
            if (res == null)
            {
                throw Contracts.ExceptNotImpl($"Unable to get a getter for column {col} of type {typeof(T1)} or {typeof(T2)} or {typeof(T3)} from schema\n{SchemaHelper.ToString(cur.Schema)}.");
            }
            return(res);
        }
Beispiel #3
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="inputSchema">existing schema</param>
        /// <param name="names">new columns</param>
        /// <param name="types">corresponding types</param>
        public TypeReplacementSchema(ISchema inputSchema, string[] names, DataViewType[] types)
        {
            _schemaInput = inputSchema;
            if (names == null || names.Length == 0)
            {
                throw Contracts.ExceptEmpty("The extended schema must contain new names.");
            }
            if (types == null || types.Length != names.Length)
            {
                throw Contracts.Except("names and types must have the same length.");
            }
            _types         = new Dictionary <int, DataViewType>();
            _mappedColumns = new Dictionary <int, int>();
            Contracts.Assert(types.Length == names.Length);
            int index;

            for (int i = 0; i < names.Length; ++i)
            {
                if (!inputSchema.TryGetColumnIndex(names[i], out index))
                {
                    throw Contracts.Except("Unable to find column '{0}' in '{1}'", names[i], SchemaHelper.ToString(inputSchema));
                }
                _types[index] = types[i];
                _mappedColumns[inputSchema.ColumnCount + i] = index;
            }
        }