public override void CLIMarshalToManaged(MarshalContext ctx)
{
var templateType = Type as TemplateSpecializationType;
var keyType = templateType.Arguments[0].Type;
var valueType = templateType.Arguments[1].Type;
var tmpVarName = "_tmp" + ctx.ArgName;
ctx.SupportBefore.WriteLine("auto {0} = gcnew System::Collections::Generic::Dictionary<{1}, {2}>();",
tmpVarName, keyType.ToString(), valueType.ToString());
ctx.SupportBefore.WriteLine("for(auto _it = {0}.Begin(); _it != {0}.End(); ++_it)", ctx.ReturnVarName);
ctx.SupportBefore.WriteStartBraceIndent();
{
ctx.SupportBefore.WriteLine("auto& _key = _it->first;");
ctx.SupportBefore.WriteLine("auto& _val = _it->second;");
var keyCtx = new MarshalContext(ctx.Driver)
{
ReturnVarName = "_key",
ReturnType = keyType
};
var valueCtx = new MarshalContext(ctx.Driver)
{
ReturnVarName = "_val",
ReturnType = valueType
};
var marshalKey = new CLIMarshalNativeToManagedPrinter(keyCtx);
keyType.Type.Visit(marshalKey);
if (!string.IsNullOrWhiteSpace(marshalKey.Context.SupportBefore))
ctx.SupportBefore.Write(marshalKey.Context.SupportBefore);
ctx.SupportBefore.WriteLine("auto _marshalKey = {0};", marshalKey.Context.Return);
var marshalValue = new CLIMarshalNativeToManagedPrinter(valueCtx);
valueType.Type.Visit(marshalValue);
if (!string.IsNullOrWhiteSpace(marshalValue.Context.SupportBefore))
ctx.SupportBefore.Write(marshalValue.Context.SupportBefore);
ctx.SupportBefore.WriteLine("auto _marshalValue = {0};", marshalValue.Context.Return);
ctx.SupportBefore.WriteLine("{0}->Add(_marshalKey, _marshalValue);", tmpVarName);
}
ctx.SupportBefore.WriteCloseBraceIndent();
ctx.Return.Write(tmpVarName);
}