// get an object's instance variable names ArrayList getInstanceVars(object instance) { ArrayList instanceVars = new ArrayList(); foreach (var name in operations.GetMemberNames(instance)) { object member = operations.GetMember(instance, name); if (!operations.IsCallable(member) && !(name == "__doc__" || name == "__module__" || name == "_object")) // found an instance variable! { instanceVars.Add(name); } } return(instanceVars); }
List <ClassInfo> generateClassInfo() { List <ClassInfo> classInformation = new List <ClassInfo>(); char[] removeEndChars = new char[2] { ',', ' ' }; foreach (KeyValuePair <string, object> obj in objects) { if (obj.Key != "__doc__" && obj.Key != "PythonUnityPrimitive") { if (obj.Value.GetType() == typeof(IronPython.Runtime.Types.OldClass)) // if the object is a class { ClassInfo classInfo = new ClassInfo(); classInfo.name = obj.Key; bool constructor = false; object classObj = obj.Value; foreach (string op in operations.GetMemberNames(classObj)) // for each of its members { string memberSignature = ""; object member = operations.GetMember(classObj, op); if (operations.IsCallable(member) && op != "update") // if it's a function (a method) and not update which is in all classes { if (op == "__init__") // constructor found { memberSignature += classInfo.name + "("; constructor = true; } else { memberSignature += op + "("; constructor = false; } object method = operations.GetMember(member, "__func__"); Type methodType = method.GetType(); PropertyInfo property = methodType.GetProperty("ArgNames", BindingFlags.Instance | BindingFlags.NonPublic); var arguments = property.GetValue(method, null) as string[]; // all parameters to the method foreach (var arg in arguments) // parameters, add to the string for the method { if (arg != "self") { memberSignature += arg + ", "; } } memberSignature = memberSignature.TrimEnd(removeEndChars); memberSignature += ")"; if (constructor) { classInfo.constructorSignature = memberSignature; } else { classInfo.methodSigs.Add(memberSignature); } } } classInformation.Add(classInfo); } } } return(classInformation); }