I'm relatively new to C#
- but come from a C/C++
background.
I need a data type (class) that is similar to DataTable
, but allows the stored columns to hold "simple" types (int, float, boolean, [string]) AS WELL as data of the same type (so that a column could hold another table which also has columns that stores tables etc).
In C++ parlance, what I am describing is something along these lines:
typedef union { /*... */ } ValueType;
typedef std::vector<ValueType> ColumnValues;
class Column
{
private:
std::string m_name ;
ColumnValues m_values;
public:
Column(const std::string& name);
// ...
}
class Table
{
private:
std::string m_name;
std::vector<Column> m_cols;
public:
Table(const std::string& name, const std::vector<Column> *cols_ptr = NULL);
// ...
};
A column can hold any valid data type - which includes a Table data type (hence the implicit infinite nesting capability).
My initial thought approach was to inherit from DataTable
- but thought I'd com in here to check if:
- If such a class already exists somewhere (either in the
.Net
library or elsewhere) - if that is the correct way of going about it
In the event that I will need to "roll my own", I would appreciate some pointers (i.e. code snippets) to help me get started.
[Edit]
Proposed usage: I intend to use this data type primarily to serialize objects in my library (so I can send them in message packets etc), but also, so I can use them as a kind of data dictionary that allows me to store data of arbitrary complexity.