Open frabe1579 opened 2 years ago
Yes, we should work on making empty be read-only. @ejsmith thoughts on above, kind of would be nice to make it truly readonly instead of returning a new instance. But would take a little bit of work.
Yeah, this is an issue. We would definitely want to return an empty read only instance and it should be the same instance for all usages to avoid allocating a dictionary.
Maybe a IReadOnlyDictionary<,>
, with appropriate extension methods, should be used when exposed for example on IQueueEntry<>
, but I don't know if it's used in other code.
I've found a potential source of bugs: the class
Foundatio.Utility.DataDictionary
exposes a static readonly fieldEmpty
to represent empty dictionaries, but it's instance is not readonly, so values can be added toEmpty
causing potential bugs. The current declaration is:A new safe declaration shoud be
This at least returns always empty dictionaries, but creates a new instance at every call. Another approach should be to re-implement DataDictionary with explicit implementation of IDictionary and IReadOnlyDictionary, or something else.