Histórico da Página
...
| Pagetitle | ||||
|---|---|---|---|---|
|
Retorna um array com o nome de todos os métodos que possuem a annotation passada como argumentoEfetua a busca da Annotation dentro de um objeto retornando uma lista contendo o(s) nome(s) do(s) método(s) onde a mesma foi encontrada.
Sintaxe
| Bloco de código | ||
|---|---|---|
| ||
Reflection.getMethodsByAnnotation( oObj,cAnnotationName ) |
...
Nome | Tipo | Descrição | Obrigatório | Referência |
|---|---|---|---|---|
oObj | objeto | Objeto na qual a busca será realizada | X | |
cAnnotationName | caractere | Nome da annotation Annotation a ser procurada | X X |
Retorno
Nome | Tipo | Descrição |
|---|---|---|
aRet | Array | Retorna um array com o nome de todos Array contendo os métodos da classe que possuem esta annotationa Annotation solicitada. Caso não encontre a array retorna vazia. |
...
Exemplo
| Bloco de código | ||||||||
|---|---|---|---|---|---|---|---|---|
| ||||||||
#INCLUDE#include "MsObjecttlpp-core.CHth" NAMESPACE TesteReflection MAIN FUNCTION Teste() ClasseTeste():New() RETURN @annotation AnnotationMethodAnnotationGetMethodsByAnnotation property1 as char @end @annotationClass AnnotationClassGetMethodsByAnnotation Public Method New() @AnnotationGetMethodsByAnnotation(property1 as char @end @AnnotationClass("testeClass") class ClasseUm public method New= "Method Annotation") Public Method MethodWithAnnotation() @AnnotationMethod@AnnotationGetMethodsByAnnotation("testeMethodproperty1 = "Method Annotation") publicPublic methodMethod testeMethodAnotherMethodWithAnnotation() endclassEndClass METHODMethod NEWNew() CLASSclass ClasseUmGetMethodsByAnnotation returnReturn selfSelf methodMethod testeMethodMethodWithAnnotation() CLASSclass ClasseUm conout("Teste de metodo") return CLASS ClasseTeste PUBLIC METHOD NEW() ENDCLASS METHOD NEW() CLASS ClasseTeste local classes := {} local methods GetMethodsByAnnotation Return Method AnotherMethodWithAnnotation() class GetMethodsByAnnotation Return Function u_testGetMethodsByAnnotation() Local aRet := {} local instance // Pego todas as classes que possuem a annotation "AnnotationClass" classes := Reflection.getClassesByAnnotation("AnnotationClass", "TesteReflection.*") conout(classes[1]) // Instancio um novo objeto desta classe instance := &(classes [1] + "():New()") // Pego todos os metodos dentro da classe que possuem a annotation "AnnotationMethod" methods as array Local oObj oObj := GetMethodsByAnnotation():New() aRet := Reflection.getMethodsByAnnotation(instanceoObj, "AnnotationMethodAnnotationGetMethodsByAnnotation") if(valType(aRet) == conout(methods[1]) // Executo o metodo encontrado &("instance:" + methods[1] + "()") RETURN self"A" .and. len(aRet) > 0) aEval(aRet,{|x| Conout(x)} ) else Conout('Nao foi encontrada Annotation com os parametros solicitados') endIf Return |
Resultado do Exemplo
TESTEREFLECTION.CLASSEUM
TESTEMETHOD
Teste de metodoANOTHERMETHODWITHANNOTATION
METHODWITHANNOTATION
Abrangência
17.3.0.3
Veja também
...
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas