C# 使用动态类循环

C# 使用动态类循环,c#,class,C#,Class,我有以下代码: public class TABLE01 { public string FIELD1 { get; set; } public string FIELD2 { get; set; } } ... // fieldlist: List<string> fieldsTABLE01 = new List<string>(); fieldsTABLE01.Add("FIELD1"); fieldsTABLE01.Add("FIELD2"); /

我有以下代码:

public class TABLE01
{
    public string FIELD1 { get; set; }
    public string FIELD2 { get; set; }
}
...
// fieldlist:
List<string> fieldsTABLE01 = new List<string>();
fieldsTABLE01.Add("FIELD1");
fieldsTABLE01.Add("FIELD2");

//response type List:
lResponseLegacy.Clear();
lResponseLegacy = DataExtract(fieldsTABLE01);

List<ClassDefinitions.TABLE01> listDataTableTABLE01 = new List<ClassDefinitions.TABLE01>();
foreach (string linea in lResponseLegacy)
{
    ClassDefinitions.TABLE01 tableTABLE01 = new ClassDefinitions.TABLE01();
    tableTABLE01.table01FIELD1 = ClassPackSupport.GetStringBetween(linea, "<FIELD1>", "</FIELD1>");
    tableTABLE01.table01FIELD2 = ClassPackSupport.GetStringBetween(linea, "<FIELD2>", "</FIELD2>");
    listDataTableTABLE01.Add(tableTABLE01);
}
classRespuestaDataclassModelo.tableTABLE01 = listDataTableTABLE01;
请给我一些小费好吗


谢谢。

你可以像这样使用反射

//Get a classes properties, you can do this with many classes.
var yourClassProperties = typeof(YourClass).GetProperties();

//And down the line:

fieldsTABLE01 = fieldsTABLE01.Concat(yourClassProperties).ToList();

你知道吗?如果我的类在引用(classdefinitions.dll)上,如何循环通过classdefinitions.dll上的所有类?您可以获得程序集信息,因此它也是公共类
//Get a classes properties, you can do this with many classes.
var yourClassProperties = typeof(YourClass).GetProperties();

//And down the line:

fieldsTABLE01 = fieldsTABLE01.Concat(yourClassProperties).ToList();