Efetua a busca de uma Annotation em um método de um objeto.
Sintaxe
Reflection.getMethodAnnotation( xParam, cMethodName, cAnnotationName )
Parâmetros
Nome | Tipo | Descrição | Obrigatório | Referência |
|---|---|---|---|---|
xParam** | objeto/caractere** | Objeto instância da classe/nome da classe** onde será procurado/a a Annotation. | X | |
cMethodName | caractere | Nome do método onde será procurada a Annotation. | X | |
cAnnotationName | caractere | Nome da Annotation que será procurada. | X |
Implementação de comportamento
A partir do build 24.3.0.0, também haverá a opção de passar simplesmente o nome da classe em xParam, conforme exemplo 2. Mas continua valendo a passagem da instância do objeto (exemplo 1).
Retorno
Nome | Tipo | Descrição |
|---|---|---|
jRet | objeto | Objeto Json com a propriedade da Annotation contendo o seu valor. Caso não encontre retorna NIL . |
Exemplos
exemplo1.tlpp
#include "tlpp-core.th"
@annotation AnnotationGetMethodAnnotation
nickname as char
@end
Class GetMethodAnnotation
Public Method New()
@AnnotationGetMethodAnnotation(nickname = "Totvs")
Public Method MethodWithAnnotation()
EndClass
Method New() class GetMethodAnnotation
Return Self
Method MethodWithAnnotation() class GetMethodAnnotation
Return
Function u_testGetMethodAnnotation()
Local oObj := GetMethodAnnotation():New()
Local jRet
jRet := Reflection.getMethodAnnotation(oObj, "MethodWithAnnotation", "AnnotationGetMethodAnnotation")
If (valType(jRet) <> 'U')
Conout(jRet["nickname"])
EndIf
Return
exemplo2.tlpp
#include "tlpp-core.th"
@annotation AnnotationGetMethodAnnotation
nickname as char
@end
Class GetMethodAnnotation
Public Method New()
@AnnotationGetMethodAnnotation(nickname = "Totvs")
Public Method MethodWithAnnotation()
EndClass
Method New() class GetMethodAnnotation
Return Self
Method MethodWithAnnotation() class GetMethodAnnotation
Return
Function u_testGetMethodAnnotation()
Local jRet
jRet := Reflection.getMethodAnnotation("GetMethodAnnotation", "MethodWithAnnotation", "AnnotationGetMethodAnnotation")
If (valType(jRet) <> 'U')
Conout(jRet["nickname"])
EndIf
Return
Resultado do Exemplo
Totvs
Abrangência
17.3.0.3
Veja também
Import HTML Content
Visão Geral
Conteúdo das Ferramentas