(You posted your workaround while I was typing this response...)
The System.Type class has a GetProperties method, which in turn takes a BindingFlags enumeration which allows you to specify if you want only public properties or protected, and if you want instance properties or static.
This returns an array of PropertyInfo objects, which belong to the System.Reflection namespace. The PropertyInfo object in turn has a GetValue method which returns the value of a current instance property as an object.
-
using System;
-
using System.Reflection;
-
class test {
-
static void Main() {
-
CurrentJoystickState joystick = new CurrentJoystickState();
-
Type JoystickType = typeof(CurrentJoystickState);
-
// Get the public properties.
-
PropertyInfo[] myPropertyInfo = JoystickType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
-
-
// Display information for all properties.
-
for (int i = 0; i < myPropertyInfo.Length; i++) {
-
PropertyInfo myPropInfo = (PropertyInfo)myPropertyInfo[i];
-
if (myPropInfo.PropertyType == typeof(int)) {
-
Console.WriteLine("The property name is {0}.", myPropInfo.Name);
-
Console.WriteLine("The property value for provided instance is {0}.", (int)myPropInfo.GetValue(joystick, null));
-
} // end if property is int
-
} // end property loop
-
} // end Main
-
}
-
The fact that you use GetProperties and not GetMethods will eliminate the procedures which return int[].
This is just to get you started. Notice that GetValue will box your 24 ints as objects. If performance is an issue, you might want to look into Reflection.Emit to generate "getters" that return strongly typed values...but that is not necessary to start, and is an entirely new topic.