Reflection and update property of in heritaed class

  • Thread starter Thread starter want 2 Learn
  • Start date Start date
W

want 2 Learn

Guest
i have a class B that inherits class A :


public class A {
public int x;
public int y;
}

public class B : A {
public int y;
}


public class g {

public string name;

public B b;

}




i want to update the fields :

//i fetch data from db

PropertyInfo[] properties = typeof(ExtraFields).GetProperties();
foreach (PropertyInfo property in properties)
{
var extraData = new B();
var class1Type = typeof(B);
try
{

class1Type.GetProperty(property.Name, BindingFlags.FlattenHierarchy |
BindingFlags.Instance |
BindingFlags.Public).SetValue(g.b, row[property.Name]);
}
catch (Exception ex)
{
int xxx = 1;
}
}

i am trying to update the fields of class A.

i get an error :

{"Column 'x' does not belong to table Table."}


1. what is wrong with the code?

2. how can i annotate some properties so they will eb skipped in this process?

Continue reading...
 
Back
Top