Closed tsimbalar closed 7 years ago
Sounds reasonable but thinking about it...
I'd assume most cases of IDictionary<TKey, TValue>
are actually Dictionary<TKey, TValue>
.
For cases where its not, i cannot judge if the custom type implements a reasonable ToString()
that is more right than using @
.
Also if i understand the documentation correctly, IDictionary<TKey, TValue>
is never serialized like Dictionary<TKey, TValue>
, even with @
.
Adding an explicit upcast cast does nothing, since checking for Dictionary<TKey, TValue>
is a runtime check anyways, but clutter the code and introduce a possible runtime exception (which goes against Serilogs design to never throw exceptions).
Awaiting final judgement from @nblumhardt
Oh, maybe I didn't understand the documentation properly ...
I had understood that this is fine
Dictionary<string, string> d = new Dictionary<..,..>() ;
Logger.Debug("{Data}", d)
... but this is not fine :
IDictionary<string, string> d = new Dictionary<..,..>() ;
Logger.Debug("{Data}", d)
... but if it's a runtime check, indeed, that is irrelevant :p
Also, one option for the codefix would be to suggest passing a new Dictionary<X,Y>(myThingThatImplementsIDictionaryOfXY)
instead of the direct object.
Yep, this is a runtime check, so probably not something SerilogAnalyzer can help with š
Ok, closing the issue, thanks ! š
From Serilog's documentation :
What this means is that to be properly destructured, dictionary parameters must be of the concrete
Dictionary<TKey, TValue>
type, so it would be useful to show a warning and a code fix for cases where aIDictionary<TKey, TValue>
or aIReadOnlyDictionary<TKey, TValue>
is provided.The fix would be, either to downcast to
Dictionary<TKey, TValue>
if that makes sense, or to suggest adding the@
destructuring operator (I'm not sure that second fix is a good idea, though).Just to be sure I didn't say anything silly or wrong : @nblumhardt am I correct with my assumptions ? :)