Is it possible to loop through the variables of a custom object?

I have an Inventory script with a custom class InventoryItem, which has a bunch of stat modifier variables. At one point in OnGUI I need to loop through an InventoryItem to look at each of its stat modifier variables, and if whatever one it is currently on is greater than zero, display it in the statistics window.

In vanilla javascript I would do something like this:

for(var key in Item){
    if(Item[key] > 0){
        doSomething();
    }
}

But in Unity I get an error: "Type 'InventoryItem' does not support slicing". Is there any way I could accomplish what I'm aiming for?

if you do for(var key in Item) it tries to enumerate the type Item, which isn't possible. You should instead create a Dictionary and iterate over that. Otherwise you could also use Reflection to achieve this.