//Definicoes das annotation, deve estar num fonte
#include "tlpp-object.th"
@annotation metodo
@end
@annotation metodoComParametro
@end
@annotation classeMetodo
@end
@classeMetodo()
Class NovaClasseMetodo
Public Data TesteAttr
@metodo()
Public Method MetodoTeste()
@metodoComParametro()
Public Method MetodoTesteComParametros(param1, param2)
Public Method New(str)
endclass
Method New(str) class NovaClasseMetodo
::TesteAttr := str
return self
Method MetodoTeste() class NovaClasseMetodo
Conout("Instancia executada: " + ::TesteAttr)
return "Banana"
Method MetodoTesteComParametros(param1, param2) class NovaClasseMetodo
Conout("-----------------------------------")
Conout("Instancia:")
Conout(::TesteAttr)
Conout("Parametros")
Conout(param1)
Conout(param2)
Conout("-----------------------------------")
return "Banana"
Main Function testeMetodo()
local ObjMethod
local classes
local obj1
local obj2
local ret
classes := Reflection.getClassesByAnnotation("classeMetodo", "") // vazio para pegar todas as classes do repositorio
obj1 := classes[1]:CreateInstance("Instancia 1")
obj2 := classes[1]:CreateInstance("Instancia 2")
ObjMethod := Reflection.getMethodsObjectByAnnotation(obj1, "metodo")
ret := ObjMethod[1]:Execute(obj1)
conout("Nome do Metodo: " + ObjMethod[1]:cMethodName)
conout("Retorno do metodo: " + ret)
ObjMethod := Reflection.getMethodsObjectByAnnotation(obj2, "metodo")
ret := ObjMethod[1]:Execute(obj2)
conout("Nome do Metodo: " + ObjMethod[1]:cMethodName)
conout("Retorno do metodo: " + ret)
ObjMethod := Reflection.getMethodsObjectByAnnotation(obj1, "metodoComParametro")
conout("Nome do Metodo: " + ObjMethod[1]:cMethodName)
ret := ObjMethod[1]:Execute(obj1, "parametro 1", "parametro 2")
conout("Retorno do metodo: " + ret)
ObjMethod := Reflection.getMethodsObjectByAnnotation(obj2, "metodoComParametro")
conout("Nome do Metodo: " + ObjMethod[1]:cMethodName)
ret := ObjMethod[1]:Execute(obj2, "parametro 1", "parametro 2")
conout("Retorno do metodo: " + ret)
return
return |