1
Answer

Reflection how to get the contents of that object

Ask a question
haezeban

haezeban

14y
2.1k
1

Hi,
public partial class Form1 : Form
    {
 private Type type;
 private Type typeItems;
 private Type typeDataSource;
 Public form1()
 {  
  typeDataSource = typeof(PremieTabel);
  typeItems = PremieTabel.Items.GetType();
  codeTabel = "PremieTabel";
  dataGridView2.DataSource = PremieTabel.Items;
  lblTitel.Text = codeTabel;
......
 }
 public btn-clickevent(object sender, EventArgs e)
 {
     // Export data to csv file
      FieldInfo[] fields = typeDataSource.GetFields();
            PropertyInfo[] properties = typeDataSource.GetProperties();
  
           
 }
 
Starting the program typeDataSource, typeItems are filled up with the Items of object PremieTabel. Also the datagrid is filled up correctly.
But we won't use reflection ( because I have the same code a lot but with the items of a different object).
In runtime I push button btn. I want to know which datasource is displayed on screen (in this case PremieTabel.Items) and get the contents
of it so I can export the contents to a csv. file.
I can check which type is in scope, but who can I get teh data of that object.
Thanks

Answers (1)