Unity Reflection / class member listing

Okay, so suppose I’ve got a class with a bunch of members like this:

class MyClass {
  var classMemberOne:int;
  var anotherClassMember:float;
  function MyClass() {
    classMemberOne = 5;
    anotherClassMember = 2.3;

I want a function listMembers(myobj) that will list the members in it like this.

var myobj:MyClass = new MyClass();
Debug.Log(listMembers(myobj)); // Should print 'classMemberOne' 'anotherClassMember' to the log.

If I made another class or passed in an existing class, it should do the same thing, regardless of the class. This seems incompatible with strict typing (how do you specify the type of input to a function like that?) but I feel confident that there’s some way around it.

Any thoughts?

Here. However, this is in C# so you have to convert it to Javascript, but it should work.

static string listmembers(Object obj)
        StringBuilder result = new StringBuilder();
        FieldInfo[] fields = obj.GetType().GetFields();
        foreach (FieldInfo field in fields)
            result.Append("'" + field.Name + "' ");
        return result.ToString();