Answer the question
In order to leave comments, you need to log in
Dynamic type declaration in C#
Greetings!
I didn't know that I would end up with such perversions.
I have a table Column1; column2; Column3 etc. The number of columns is dynamic by definition.
I need to make sure that all this is present in the program in the form of an array with elements that contain the names of the columns as class fields (it is important that these are fields, not an array and nothing else). For example, he gave an anonymous call of a similar thing
[] {Column1=foo1, Column2=foo2, Column3=foo3 etc...}
Answer the question
In order to leave comments, you need to log in
You can try to use class code generation based on simply listing field names with types (or even immediately based on the table structure in the database), for example, using t4 text templates .
The class template will need to be written once, in the future it will be updated during assembly.
This method does not work if the table structure changes after the program is compiled.
If the data type for your field is object, then you can safely send anything there, even if it’s a double. Information about the type of an object is saved, so you can find out what type you have at any time. Regarding the number of columns, there are already a lot of options. Need to be more specific about what exactly you want to get in the end? An example of working with data inside and out, so to speak.
There is a control www.devexpress.com/Products/NET/Controls/WPF/Grid/tree.xml which only understands such a specific data representation as input. That is why I need it in such a strange form.
The code is something like this (well, a bunch of strapping around, but it doesn't matter)
//формируем коллекцию используя БД и SQL команду
TreeViewSQLiteDataCollection collection= new TreeViewSQLiteDataCollection (sqLiteCommandString, sqLiteConnection);
//это вызывается в коде TreeViewSQLiteDataCollection для того чтобы наполнить коллекцию из открытого датаридера
this.Add(new { path = sqlReader.GetString(0), parent_ID = sqlReader.GetString(1), ShowID = sqlReader.GetString(0), description = sqlReader.GetInt32(2) });
//привязываем коллекцию к контролу
treeListControl1.ItemsSource = collection;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question