I have a dictionary that contains different kinds of values and I want to filter for an item that has a specific sub-type and that satisfies a certain condition:
var
FData: IDictionary<TGUID, TObject>; // Polymorphic
begin
TMicroStep(FData.Values.Single(
function(const O: TObject): Boolean begin
Result := (O is TMicroStep) and (TMicroStep(O).OrderTag = 1);
end))
end;
It works, but it looks ugly, because of the type check and double cast.
Maybe something like this might be possible?
var
FData: IDictionary<TGUID, TObject>; // Polymorphic
begin
FData.Values.SingleSubType<TMicroStep>(
function(const MS: TMicroStep): Boolean begin
Result := MS.OrderTag = 1;
end))
end;
Does Spring have anything that can help me here?