Reflection - How to box a class/object instance?
Monkey Forums/Monkey Beginners/Reflection - How to box a class/object instance?
| ||
Hello everyone, I have (hopefully) a simple question; how do I box a class/object instance? What I mean is, to box an int, I'd use BoxInt(), and for a string I'd use BoxString(), but what if I want to box an instance of one of my own classes? There doesn't seem to be a BoxObject() function. |
| ||
Just cast them to an object?Local obj:Object = Object(New MyType()) |
| ||
you don't need to down cast it. Every object created extends from the "Object" class. this works: local obj:Object = new MyType() you do need to up cast it though: Local this:MyType = MyType(obj) |
| ||
Thanks everyone, what I was missing was that the point of the BoxInt() etc methods is to package the built-in types as objects. So if you already have an object, the object can just be used directly. |
| ||
you can use "Property" if you need getters/setters. |