I've a DataGridView
with many rows each row contains two cells ,
when cell[0]= name
and cell[1]= value
correspond to a member in a class (also have the exact same name )
and I want to use reflection to set the properties of that class using the DataGridView
like this :
using question from c# - How to iterate through classes fields and set properties
GlobalParam.Params2 ParseDataGridForClass(System.Windows.Forms.DataGridView DataGrid)
{
GlobalParam.Params2 NewSettings2 = new GlobalParam.Params2();
foreach (System.Windows.Forms.DataGridViewRow item in DataGrid.Rows)
{
if (item.Cells[0].Value != null && item.Cells[1].Value != null)
{
Type T = NewSettings2.GetType();
PropertyInfo info = T.GetProperty(item.Cells[0].Value.ToString());
if (!info.CanWrite)
continue;
info.SetValue(NewSettings2,
item.Cells[1].Value.ToString(),null);
}
}
return NewSettings2;
}
NewSettings look like
struct NewSettings
{
string a { get; set; }
string b { get; set; }
string c { get; set; }
}
when iterating through I see that none of the properties get's changed meaning NewSettings remains null in all of it's properties
what can be the problem ?