public static void EmitMarshalAction(CodeBlockBuilder codeBlock, Generation.AssignAction action, Action <ExpressionBuilder> targetExpression) { switch (action.Type) { case AssignActionType.Assign: codeBlock.EmitAssignment(targetExpression, action.ValueExpression); break; case AssignActionType.Alloc: if (action.LengthExpression != null) { codeBlock.EmitAssignment(targetExpression, Cast(action.MemberType + "*", StaticCall("Interop.HeapUtil", $"Allocate<{action.MemberType}>", action.LengthExpression))); } else { codeBlock.EmitAssignment(targetExpression, Cast(action.MemberType + "*", StaticCall("Interop.HeapUtil", $"Allocate<{action.MemberType}>"))); } break; case AssignActionType.AllocAndAssign: codeBlock.EmitAssignment(targetExpression, Cast(action.MemberType + "*", StaticCall("Interop.HeapUtil", $"Allocate<{action.MemberType}>"))); codeBlock.EmitAssignment(Deref(targetExpression), action.ValueExpression); break; case AssignActionType.MarshalToAddressOf: codeBlock.EmitCall(action.ValueExpression, "MarshalTo", AddressOf(targetExpression)); break; case AssignActionType.MarshalTo: codeBlock.EmitAssignment(targetExpression, Cast(action.MemberType + "*", StaticCall("Interop.HeapUtil", $"Allocate<{action.MemberType}>"))); codeBlock.EmitCall(action.ValueExpression, "MarshalTo", targetExpression); break; case AssignActionType.MarshalFrom: codeBlock.EmitAssignment(targetExpression, StaticCall(action.MemberType, "MarshalFrom", action.ValueExpression)); break; case AssignActionType.MarshalFromAddressOf: codeBlock.EmitAssignment(targetExpression, StaticCall(action.MemberType, "MarshalFrom", AddressOf(action.ValueExpression))); break; case AssignActionType.FixedLengthMarshalTo: codeBlock.EmitStaticCall("Interop.HeapUtil", "MarshalTo", action.ValueExpression, action.LengthExpression, targetExpression); break; } }