public IList <ProtoDataColumn> GetColumns(
            IDataReader reader,
            ProtoDataWriterOptions options)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            using (DataTable schema = reader.GetSchemaTable())
            {
                bool schemaSupportsExpressions = schema.Columns.Contains("Expression");

                var columns = new List <ProtoDataColumn>(schema.Rows.Count);
                for (int i = 0; i < schema.Rows.Count; i++)
                {
                    // Assumption: rows in the schema table are always ordered by
                    // Ordinal position, ascending
                    DataRow row = schema.Rows[i];

                    // Skip computed columns unless requested.
                    if (schemaSupportsExpressions)
                    {
                        bool isComputedColumn;

                        if (IsRunningOnMono)
                        {
                            isComputedColumn = Equals(row["Expression"], string.Empty);
                        }
                        else
                        {
                            isComputedColumn = !(row["Expression"] is DBNull);
                        }

                        if (isComputedColumn && !options.IncludeComputedColumns)
                        {
                            continue;
                        }
                    }

                    var col = new ProtoDataColumn
                    {
                        ColumnIndex   = i,
                        ProtoDataType = ConvertProtoDataType.FromClrType((Type)row["DataType"]),
                        ColumnName    = (string)row["ColumnName"]
                    };

                    columns.Add(col);
                }

                return(columns);
            }
        }
Exemple #2
0
        public static IList <ProtoDataColumn> GetColumns(IDataReader reader, ProtoDataWriterOptions options)
        {
            using (var schemaTable = reader.GetSchemaTable())
            {
                var schemaSupportsExpressions = schemaTable.Columns.Contains("Expression");

                var columns = new List <ProtoDataColumn>(schemaTable.Rows.Count);

                for (var i = 0; i < schemaTable.Rows.Count; i++)
                {
                    // Assumption: rows in the schema table are always ordered by
                    // Ordinal position, ascending
                    var row = schemaTable.Rows[i];

                    // Skip computed columns unless requested.
                    if (schemaSupportsExpressions)
                    {
                        bool isComputedColumn;

                        if (IsRunningOnMono)
                        {
                            isComputedColumn = Equals(row["Expression"], string.Empty);
                        }
                        else
                        {
                            isComputedColumn = !(row["Expression"] is DBNull);
                        }

                        if (isComputedColumn && !options.IncludeComputedColumns)
                        {
                            continue;
                        }
                    }

                    var columnName       = (string)row["ColumnName"];
                    var dataType         = (Type)row["DataType"];
                    var protoBufDataType = ConvertProtoDataType.FromClrType(dataType);

                    columns.Add(new ProtoDataColumn(columnName, dataType, protoBufDataType));
                }

                return(columns);
            }
        }