Reputation: 51
I'm making an Save Version checker and if version doesn't match transport old variable values into new.
I have this class
[System.Serializable]
public class SavePattern
{
public int SaveVersion = 1;
public string Name;
public int Electricity;
public string[] Inventory;
}
I want to loop all public variables of class and be able to use it like key and value variable.
Upvotes: 2
Views: 1574
Reputation: 5020
you can loop your class variable by using System.Reflection;
SavePattern savePatt = new SavePattern();
PropertyInfo[] properties = typeof(SavePattern).GetProperties();
foreach (PropertyInfo property in properties)
{
var val = property.GetValue(savePatt);
}
Upvotes: 2