Skip to main content
added 398 characters in body
Source Link
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

You should not be calling it a dictionary because you changed the expected behaviour of the IDictionary interface. The MSDN clearly states that the getter of the indexer should throw an exception if the key is not found.

KeyNotFoundException - The property is retrieved and key is not found.

this should not be adding new elements if the getter is used. The closest collection type that has a similar behaviour would be the ILookup but even this doesn't seem to be right in this case - a lookup returns an empty collection but does not change the lookup itself.

I suggest naming it a MultiCollection and documenting the unexpected side effects of the getter. This collection does not need to implement the IDictionary interface because you use only the indexer anyway. IEnumerable would be enough so that you can use it a loop.


You are also doing other things that are very unusual for C#.

For example you use a plural name for the enum. We do this only if it is also decorated with the FlagsAttribute that indicates that the values can be combined.

Another strange naming convention is the <keyType, contentType>. C# uses a T prefix for generic types so the correct names should be: <TKey, TContent>.

You should not be calling it a dictionary because you changed the expected behaviour of the IDictionary interface. The MSDN clearly states that the getter of the indexer should throw an exception if the key is not found.

KeyNotFoundException - The property is retrieved and key is not found.

this should not be adding new elements if the getter is used. The closest collection type that has a similar behaviour would be the ILookup but even this doesn't seem to be right in this case - a lookup returns an empty collection but does not change the lookup itself.

I suggest naming it a MultiCollection and documenting the unexpected side effects of the getter. This collection does not need to implement the IDictionary interface because you use only the indexer anyway. IEnumerable would be enough so that you can use it a loop.

You should not be calling it a dictionary because you changed the expected behaviour of the IDictionary interface. The MSDN clearly states that the getter of the indexer should throw an exception if the key is not found.

KeyNotFoundException - The property is retrieved and key is not found.

this should not be adding new elements if the getter is used. The closest collection type that has a similar behaviour would be the ILookup but even this doesn't seem to be right in this case - a lookup returns an empty collection but does not change the lookup itself.

I suggest naming it a MultiCollection and documenting the unexpected side effects of the getter. This collection does not need to implement the IDictionary interface because you use only the indexer anyway. IEnumerable would be enough so that you can use it a loop.


You are also doing other things that are very unusual for C#.

For example you use a plural name for the enum. We do this only if it is also decorated with the FlagsAttribute that indicates that the values can be combined.

Another strange naming convention is the <keyType, contentType>. C# uses a T prefix for generic types so the correct names should be: <TKey, TContent>.

added 143 characters in body
Source Link
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

You should not be calling it a dictionary because you changed the expected behaviour of the IDictionary interface. The MSDN clearly states that the getter of the indexer should throw an exception if the key is not found.

KeyNotFoundException - The property is retrieved and key is not found.

this should not be adding new elements if the getter is used. The closest collection type that has a similar behaviour would be the ILookup but even this doesn't seem to be right in this case - a lookup returns an empty collection but does not change the lookup itself.

I suggest naming it a MultiCollection and documenting the unexpected side effects of the getter. This collection does not need to implement the IDictionary interface because you use only the indexer anyway. IEnumerable would be enough so that you can use it a loop.

You should not be calling it a dictionary because you changed the expected behaviour of the IDictionary interface. The MSDN clearly states that the getter of the indexer should throw an exception if the key is not found.

KeyNotFoundException - The property is retrieved and key is not found.

this should not be adding new elements if the getter is used. The closest collection type that has a similar behaviour would be the ILookup but even this doesn't seem to be right in this case - a lookup returns an empty collection but does not change the lookup itself.

I suggest naming it a MultiCollection and documenting the unexpected side effects of the getter.

You should not be calling it a dictionary because you changed the expected behaviour of the IDictionary interface. The MSDN clearly states that the getter of the indexer should throw an exception if the key is not found.

KeyNotFoundException - The property is retrieved and key is not found.

this should not be adding new elements if the getter is used. The closest collection type that has a similar behaviour would be the ILookup but even this doesn't seem to be right in this case - a lookup returns an empty collection but does not change the lookup itself.

I suggest naming it a MultiCollection and documenting the unexpected side effects of the getter. This collection does not need to implement the IDictionary interface because you use only the indexer anyway. IEnumerable would be enough so that you can use it a loop.

Source Link
t3chb0t
  • 44.3k
  • 9
  • 84
  • 190

You should not be calling it a dictionary because you changed the expected behaviour of the IDictionary interface. The MSDN clearly states that the getter of the indexer should throw an exception if the key is not found.

KeyNotFoundException - The property is retrieved and key is not found.

this should not be adding new elements if the getter is used. The closest collection type that has a similar behaviour would be the ILookup but even this doesn't seem to be right in this case - a lookup returns an empty collection but does not change the lookup itself.

I suggest naming it a MultiCollection and documenting the unexpected side effects of the getter.