public override void CLIMarshalToNative(MarshalContext ctx)
{
var templateType = Type as TemplateSpecializationType;
var type = templateType.Arguments[0].Type;
var entryString = (ctx.Parameter != null) ? ctx.Parameter.Name : ctx.ArgName;
var tmpVarName = "_tmp" + entryString;
var cppTypePrinter = new CppTypePrinter(ctx.Driver.TypeDatabase);
var nativeType = type.Type.Visit(cppTypePrinter);
ctx.SupportBefore.WriteLine("auto {0} = Vector<{1}>();",
tmpVarName, nativeType);
ctx.SupportBefore.WriteLine("for each({0} _element in {1})",
type.ToString(), entryString);
ctx.SupportBefore.WriteStartBraceIndent();
{
var param = new Parameter
{
Name = "_element",
QualifiedType = type
};
var elementCtx = new MarshalContext(ctx.Driver)
{
Parameter = param,
ArgName = param.Name,
};
var marshal = new CLIMarshalManagedToNativePrinter(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}.Push(_marshalElement);", tmpVarName);
}
ctx.SupportBefore.WriteCloseBraceIndent();
ctx.Return.Write(tmpVarName);
}