During the project (.NET Framework 'I belive' 4.6.2) at work i meet interesting and confusing behavior:
var dict = new Dictionary<string, Dictionary<string, SomeFunnyStuff>>();
// Dictionary hard working collector
this funny dict was past to the class but as programmer learn some years ago: 'You should always base your classes on abstractions' (that was voice in my head ^_^) I create class like so:
internal class SampleStackoverflowClass
{
public IDictionary<string, IDictionary<string, SomeFunnyStuff>> TransformationDictionary { get; }
// Just for simplify
public SampleStackoverflowClass(IDictionary<string, IDictionary<string, SomeFunnyStuff>> transformation)
{
TransformationDictionary = transformation;
}
// some extremely enterprise logic ...
}
Ant them when we wanna pass the dictionary:
var sample = new SampleStackoverflowClass(dict);
We got:
Argument 1: cannot convert from System.Collections.Generic.Dictionary>' to 'System.Collections.Generic.IDictionary>
What seams weird becouse we got covariance and contravariance in C# 4.0 if I am not wrong.
So i come back to home after that stunning (at least for me :-)) discover start testing even the totally basic staff like (It works):
IEnumerable<IEnumerable<IEnumerable<object>>> working = new List<List<List<string>>>();
and after that create .NET Core (3.1) project and test gives the same results which feels odd.
So my questions:
- I this normal behavior or lack of tests? (Not to much people create Dictionary of Dictionary ^_^)
- If it's normal can someone explain the bright idea behind it? (Meaning Why it is not allow? maybe some MSIL problems Or CLR ones I belive someone can rationally explain that if that was planed behavior)
Thanks for time spending 4