Is there an easy way to copy the TDictionary content into another?
If you want to go even further, here's another approach:
type
TDictionaryHelpers<TKey, TValue> = class
public
class procedure CopyDictionary(ASource, ATarget: TDictionary<TKey,TValue>);
end;
...implementation...
{ TDictionaryHelpers<TKey, TValue> }
class procedure TDictionaryHelpers<TKey, TValue>.CopyDictionary(ASource,
ATarget: TDictionary<TKey, TValue>);
var
LKey: TKey;
begin
for LKey in ASource.Keys do
ATarget.Add(LKey, ASource.Items[ LKey ] );
end;
usage according to your definition of Key and Value:
TDictionaryHelpers<TItemKey, TItemData>.CopyDictionary(LSource, LTarget);
TDictionary has a constructor that allows you to pass in another collection object, which will create the new one by copying the contents of the original. Is that what you are looking for?
constructor Create(Collection: TEnumerable<TPair<TKey,TValue>>); overload;
So you would use
Target := TItems.Create(Source);
And Target would be created as a copy of Source (or at least contain all the items in Source).