Made anything interesting with Reflection?

BlitzMax Forums/BlitzMax Programming/Made anything interesting with Reflection?

grable(Posted 2008) [#1]
Ive tried to find a clever use for this Reflection thing.
so far ive cloned types, made a generic serializer and even simulated interfaces.

What have you been using Reflection for, if at all?


Brucey(Posted 2008) [#2]
I've used it for my Unit Testing module.

Previously, creating a test involved function pointers and manually adding tests to a suite. With reflection, it takes all the effort out of writing them, so you can concentrate on the testing instead.

For example, by extending from a TTest type, that type is automagically included for testing.
Methods can be called anything you like, you just tag them with {test} ...
Method testAdd() { test }
End Method

Reflection does the rest :-)


Dreamora(Posted 2008) [#3]
I have interface implementation.

Type Test { implementes=Test1,Test2 }

End Type

and a given function call in the new method.
That will test at creation if the type really implements all the functionality of those 2.

There is as well a method that checks if a given object implements a given type and if a given class implements a given type

for real usage this would need to be compiler level stuff sadly, using BMK is no option as the bmk isn't designed for this kind of extension due to its code processing.


Azathoth(Posted 2008) [#4]
A clone function that can clone any Type.


grable(Posted 2008) [#5]
I have something along the same lines with interfaces, and i think it turned out pretty good. dont know how fast it is though, with TMethod.Invoke() and the extra method call.
But with a few macros to ease the creation of interface types its at least usable ;)
' this generates the type below
'Interface(ITable)
'	IMethod( Lookup, :String, name:String)
'EndInterface()
Type ITable Extends TInterface
	Field intf_Lookup:TMethod
	Method Lookup:String(name:string)
		Return intf_Read.Invoke( _intf_This, [name])
	EndMethod
EndType

Type TTable {implements="ITable"}
	Method Lookup:String( name:string)
		Print "TTable.Lookup()"
	EndMethod
EndType

Local obj:TTable= New TTable
Local intf:ITable = ITable( QueryInterface( obj, "ITable"))
If intf Then intf.Lookup("")

As you can guess, QueryInterface() does all the job of filling in the interface object with the proper TMethod objects,
so its really just a proxy... i want me some real shiny interfaces!


Blueapples(Posted 2008) [#6]
Reflection is proving very useful for a framework I am working on. More details some day - it's just a part of a large project I've started recently. Basically I'm using it to make it a lot easier to write regular applications (or even games if I extend the framework) with BlitzMax.


marksibly(Posted 2008) [#7]
Hi,

I'm just finishing up a lua->bmx binding thing that uses reflection to allow lua code to invoke/access any bmx methods/fields - way cool!


CS_TBL(Posted 2008) [#8]
Will there ever be a reflection tutorial written in the same n00b-style as B+'s first Hello World examples?


skn3(Posted 2008) [#9]
What the hell. Since when has the reflection stuff actualy been in a public release ?

That one slipped past my radar. cool!


Beaker(Posted 2008) [#10]
CS_TBL - have you had a look at the help for reflection? It's under "modules\BASIC".


Jake L.(Posted 2008) [#11]
Used reflection to serialize classes to xml and reverse. Works like a charme.


FlameDuck(Posted 2008) [#12]
Persistence Framework.


JoshK(Posted 2008) [#13]
Is there any documentation on how this actually works?


Brucey(Posted 2008) [#14]
Like what Beaker said.