C# Iterate through Class properties

前端 未结 4 925
猫巷女王i
猫巷女王i 2020-11-29 16:43

I\'m currently setting all of the values of my class object Record.

This is the code that I\'m using to populate the record at the moment, property by p

4条回答
  •  误落风尘
    2020-11-29 17:31

    I tried what Samuel Slade has suggested. Didn't work for me. The PropertyInfo list was coming as empty. So, I tried the following and it worked for me.

        Type type = typeof(Record);
        FieldInfo[] properties = type.GetFields();
        foreach (FieldInfo property in properties) {
           Debug.LogError(property.Name);
        }
    

提交回复
热议问题