This question already has an answer here:
How to get all fields from SuperClass1
by reflection?
namespace ConsoleApplication9
{
class Program
{
static void Main(string[] args)
{
SuperClass1.SubClass1 class1 = new SuperClass1.SubClass1();
SuperClass2.SubClass2 class2 = new SuperClass2.SubClass2();
PrintAllFields(class1);
}
public static void PrintAllFields(object obj)
{
var SuperClassType = obj.GetType();
SuperClassType.GetFields();
}
}
public class SuperClass1
{
public int param1;
public int param2;
public int param3;
public class SubClass1
{
public int paramTest;
}
}
public class SuperClass2
{
public int param4;
public int param5;
public class SubClass2
{
public int paramTest;
}
}
}
Aucun commentaire:
Enregistrer un commentaire