public ConstructedValueExpression Compile(MapTypeContext context)
        {
            if (!IsSupportedType(context.TargetType))
            {
                return(ConstructedValueExpression.Nothing);
            }

            var genericArguments = context.TargetType.GetGenericArguments();

            Debug.Assert(genericArguments.Length == 2);

            var keyType = typeof(string);

            Debug.Assert(genericArguments[0] == typeof(string));

            var elementType = context.TargetType.GetGenericArguments()[1];

            Debug.Assert(elementType != null);

            var typeInfo = GetConcreteTypeInfo(context, keyType, elementType);
            var dictType = typeInfo.ConcreteType;

            Debug.Assert(dictType != null);

            var constructor = typeInfo.Constructor;

            Debug.Assert(constructor != null);

            var addMethod = typeInfo.AddMethod;

            Debug.Assert(addMethod != null);

            var concreteState = context.ChangeTargetType(dictType);
            var dictVar       = DictionaryExpressionFactory.GetMaybeInstantiateDictionaryExpression(concreteState, constructor);
            var addStmts      = DictionaryExpressionFactory.AddDictionaryPopulateStatements(_valueCompiler, concreteState, elementType, dictVar.FinalValue, addMethod);

            return(new ConstructedValueExpression(
                       dictVar.Expressions.Concat(addStmts.Expressions),
                       Expression.Convert(dictVar.FinalValue, context.TargetType),
                       dictVar.Variables.Concat(addStmts.Variables)
                       ));
        }
        public ConstructedValueExpression Compile(MapTypeContext context)
        {
            if (!IsSupportedType(context.TargetType))
            {
                return(ConstructedValueExpression.Nothing);
            }

            var idictType   = GetIDictionaryType(context);
            var elementType = idictType.GetGenericArguments()[1];

            var constructor = GetDictionaryConstructor(context.TargetType);
            var addMethod   = GetIDictionaryAddMethod(context.TargetType, idictType);

            var dictVar  = DictionaryExpressionFactory.GetMaybeInstantiateDictionaryExpression(context, constructor);
            var addStmts = DictionaryExpressionFactory.AddDictionaryPopulateStatements(_valueCompiler, context, elementType, dictVar.FinalValue, addMethod);

            return(new ConstructedValueExpression(
                       dictVar.Expressions.Concat(addStmts.Expressions),
                       Expression.Convert(dictVar.FinalValue, context.TargetType),
                       dictVar.Variables.Concat(addStmts.Variables)));
        }