hi all
I've some problems using custom attributes.
I declared a register procedure as
...
{ TBomt_HashServiceList }
TBomt_HashServiceList = specialize TFPGMap<string,TBomt_Service>;
...
var
ServiceList: TBomt_HashServiceList;
procedure Bomt_RegisterService(const AClassService: TClass);
var Context : TRttiContext;
AType : TRttiType;
Attribute : TCustomAttribute;
begin
Context := TRttiContext.Create;
try
AType := Context.GetType(typeinfo(AClassService));
for Attribute in AType.GetAttributes do begin
if Attribute is TBomt_ServiceAttribute then begin
writeln('attr: ', TBomt_ServiceAttribute(Attribute).EndPoint);
ServiceList[TBomt_ServiceAttribute(Attribute).EndPoint]:= TBomt_Service(AClassService);
end;
end;
finally
Context.Free
end;
end;
and in initialization section
initialization
ServiceList:=TBomt_HashServiceList.Create;
Bomt_RegisterService(TBomt_Service);
but my code is wrong as no attributes were detected.
I attached a complete test project to help.
Thanks in advance.
nomorelogic
Edit:
PS: note in test project there's a second unit with same initializazion code
executing I expect to have 2 registration