public override void CLIMarshalToManaged(MarshalContext ctx) { var templateType = Type as TemplateSpecializationType; var type = templateType.Arguments[0].Type; var tmpVarName = "_tmp" + ctx.ArgName; ctx.SupportBefore.WriteLine("auto {0} = gcnew System::Collections::Generic::List<{1}>();", tmpVarName, type.ToString()); ctx.SupportBefore.WriteLine("for(auto _element : {0})", ctx.ReturnVarName); ctx.SupportBefore.WriteStartBraceIndent(); { var elementCtx = new MarshalContext(ctx.Driver) { ReturnVarName = "_element", ReturnType = type }; var marshal = new CLIMarshalNativeToManagedPrinter(elementCtx); type.Type.Visit(marshal); if (!string.IsNullOrWhiteSpace(marshal.Context.SupportBefore)) { ctx.SupportBefore.Write(marshal.Context.SupportBefore); } ctx.SupportBefore.WriteLine("auto _marshalElement = {0};", marshal.Context.Return); ctx.SupportBefore.WriteLine("{0}->Add(_marshalElement);", tmpVarName); } ctx.SupportBefore.WriteCloseBraceIndent(); ctx.Return.Write(tmpVarName); }
public override void CLIMarshalToManaged(MarshalContext ctx) { var desugared = Type.Desugar(); var templateType = desugared as TemplateSpecializationType; var type = templateType.Arguments[0].Type; var isPointerToPrimitive = type.Type.IsPointerToPrimitiveType(); var managedType = isPointerToPrimitive ? new CILType(typeof(System.IntPtr)) : type.Type; var tmpVarName = "_tmp" + ctx.ArgName; ctx.Before.WriteLine( "auto {0} = gcnew ::System::Collections::Generic::List<{1}>();", tmpVarName, managedType); string retVarName = "__list" + ctx.ParameterIndex; ctx.Before.WriteLine($@"auto {retVarName} = {( ctx.ReturnType.Type.Desugar().IsPointer() ? $"*{ctx.ReturnVarName}" : ctx.ReturnVarName)};"); ctx.Before.WriteLine($"for(auto _element : {retVarName})"); ctx.Before.WriteOpenBraceAndIndent(); { var elementCtx = new MarshalContext(ctx.Context, ctx.Indentation) { ReturnVarName = "_element", ReturnType = type }; var marshal = new CLIMarshalNativeToManagedPrinter(elementCtx); type.Type.Visit(marshal); if (!string.IsNullOrWhiteSpace(marshal.Context.Before)) { ctx.Before.Write(marshal.Context.Before); } ctx.Before.WriteLine("auto _marshalElement = {0};", marshal.Context.Return); if (isPointerToPrimitive) { ctx.Before.WriteLine("{0}->Add({1}(_marshalElement));", tmpVarName, managedType); } else { ctx.Before.WriteLine("{0}->Add(_marshalElement);", tmpVarName); } } ctx.Before.UnindentAndWriteCloseBrace(); ctx.Return.Write(tmpVarName); }