Reflection.getDataAnnotationList
Retorna um array contendo as Annotations atribuídas a uma propriedade de um objeto.
Sintaxe
Reflection.getDataAnnotationList( xParam, cPropertyName )
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 | |
cPropertyName | caractere | Indica o nome da propriedade onde será procurada a Annotation | 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 |
---|---|---|
aRet | Array | Array contendo em cada posição um objeto Json contendo o valor de cada Annotation atribuída a propriedade do objeto. Caso nenhuma Annotation seja encontrada, retorna NIL. |
Exemplos
exemplo1.tlpp
#include "tlpp-core.th" @annotation AnnotationGetDataAnnotationList01 teste1 as char @end @annotation AnnotationGetDataAnnotationList02 teste2 as char @end Class GetDataAnnotationList @AnnotationGetDataAnnotationList01(teste1 = "Primeira Annotation") @AnnotationGetDataAnnotationList02(teste2 = "Segunda Annotation") Public data data1 Public Method New() EndClass Method New() class GetDataAnnotationList Return Self Function u_testGetDataAnnotationList() Local oObj := GetDataAnnotationList():New() Local aRet as array aRet := Reflection.getDataAnnotationList(oObj,"data1") Conout(aRet[1]["teste1"]) Conout(aRet[2]["teste2"]) Return
exemplo2.tlpp
#include "tlpp-core.th" @annotation AnnotationGetDataAnnotationList01 teste1 as char @end @annotation AnnotationGetDataAnnotationList02 teste2 as char @end Class GetDataAnnotationList @AnnotationGetDataAnnotationList01(teste1 = "Primeira Annotation") @AnnotationGetDataAnnotationList02(teste2 = "Segunda Annotation") Public data data1 Public Method New() EndClass Method New() class GetDataAnnotationList Return Self Function u_testGetDataAnnotationList() Local aRet as array aRet := Reflection.getDataAnnotationList(GetDataAnnotationList,"data1") Conout(aRet[1]["teste1"]) Conout(aRet[2]["teste2"]) Return
Resultado do Exemplo
Primeira Annotation
Segunda Annotation
Abrangência
17.3.0.3
Veja também
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas