Fórum rtti - typecast #499158
26/10/2014
0
estou fazendo alguns testes para montar um framework...
a rotina abaixo esta funcionando corretamente...
class function TGenericDAO.GetTableName<T>(Obj: T): String;
var
Contexto: TRttiContext;
TypObj: TRttiType;
Atributo: TCustomAttribute;
begin
Contexto := TRttiContext.Create;
TypObj := Contexto.GetType(TObject(Obj).ClassInfo);
for Atributo in TypObj.GetAttributes do
begin
if Atributo is TableName then
Exit(TableName(Atributo).Name);
end;
end;
ocorre que tenho uma outra rotina que é identica a essa, mudando apenas o nome da funcao e o bloco do if...
essa outra funcao seria...
class function TGenericDAO.GetGeneratorName<T>(Obj: T): String;
e mudaria o if...
if Atributo is GeneratorName then
Exit(GeneratoName(Atributo).Name);
gostaria de saber, tentei, mas ainda nao consegui...
se tem como passar esse if como parametro, generics, metodo anonimo...
nao quero colocar um else...
e nem um in..
valeu
a rotina abaixo esta funcionando corretamente...
class function TGenericDAO.GetTableName<T>(Obj: T): String;
var
Contexto: TRttiContext;
TypObj: TRttiType;
Atributo: TCustomAttribute;
begin
Contexto := TRttiContext.Create;
TypObj := Contexto.GetType(TObject(Obj).ClassInfo);
for Atributo in TypObj.GetAttributes do
begin
if Atributo is TableName then
Exit(TableName(Atributo).Name);
end;
end;
ocorre que tenho uma outra rotina que é identica a essa, mudando apenas o nome da funcao e o bloco do if...
essa outra funcao seria...
class function TGenericDAO.GetGeneratorName<T>(Obj: T): String;
e mudaria o if...
if Atributo is GeneratorName then
Exit(GeneratoName(Atributo).Name);
gostaria de saber, tentei, mas ainda nao consegui...
se tem como passar esse if como parametro, generics, metodo anonimo...
nao quero colocar um else...
e nem um in..
valeu
Felipe Barros
Curtir tópico
+ 0
Responder
Clique aqui para fazer login e interagir na Comunidade :)