//Definicoes das annotation, deve estar num fonte
#include "tlpp-object.th"
@annotation metodoclasse
@end
@annotation metodoComParametroattr
@end
@annotation classeMetodo
@end
@classeMetodo
@classe()
Class NovaClasseMetodo
NovaClasse
@attr()
Public Data TesteAttr
as
@metodo()
char
Public Method MetodoTeste()
@metodoComParametro()
Public Method MetodoTesteComParametros(param1, param2)
Public Method New(str)
endclass
Method New(str) class NovaClasseMetodo
NovaClasse
::TesteAttr := str
return self
Method MetodoTeste() class NovaClasseMetodo
NovaClasse
Conout("Instancia executada: " + ::TesteAttr)
return "Banana"
Main
MethodFunction MetodoTesteComParametrostesteNovo(param1, param2) class NovaClasseMetodo
Conout("-----------------------------------")
Conout("Instancia:")
Conout(::TesteAttr)
Conout("Parametros")
Conout(param1)
Conout(param2)
Conout("---------)
local AttrA
local obj1 := NovaClasse():New("Instancia 1")
local obj2 := NovaClasse():New("Instancia 2")
Conout("--------------------------")
return "Banana"
Main Function testeMetodo()
local ObjMethod
local classes
local obj1
local obj2
local ret
classes ")
AttrA := Reflection.getClassesByAnnotationgetAttributesByAnnotation("classeMetodo"obj1, "attr") // vazio para pegar todas as classes do repositorio
obj1 := classes
Conout(AttrA[1]:CreateInstance("Instancia 1")
obj2 := classesGetValue(obj1))
AttrA[1]:CreateInstance("Instancia 2")
ObjMethod := Reflection.getMethodsObjectByAnnotation(Assign(obj1, "metodoBanana1")
ret := ObjMethod Conout(AttrA[1]:Execute(obj1cAttributeName)
conout("Nome do Metodo: " + ObjMethod Conout(AttrA[1]:cMethodNamecAttributeType)
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)
Conout(obj1:TesteAttr)
Conout("-----------------------")
Conout("-----------------------")
AttrA := Reflection.getAttributesByAnnotation(obj2, "attr")
Conout(AttrA[1]:GetValue(obj2))
AttrA[1]:Assign(obj2, "Banana2")
Conout(AttrA[1]:cAttributeName)
Conout(AttrA[1]:cAttributeType)
Conout(obj2:TesteAttr)
Conout("-----------------------")
return |