private static void EmitInvokeCommand(CodeBlockBuilder tryBlock, TypeSet.VkHandleMethod method, Func <IEnumerable <Action <ExpressionBuilder> >, Action <ExpressionBuilder> > commandExpression, Func <TypeSet.VkMethodParam, string> argumentNameSelector, string commandResultVariable) { foreach (var fixedArgument in method.Parameters.Where(x => !string.IsNullOrEmpty(x.FixedName))) { tryBlock.EmitStatement($"fixed({fixedArgument.FixedType} {fixedArgument.FixedName} = {fixedArgument.Name})"); } var arguments = method.Parameters.Select(argumentNameSelector).Select(Variable); if (method.IsPassthroughResult) { tryBlock.EmitAssignment(Variable("result"), commandExpression(arguments)); } else if (method.HasVkResult) { tryBlock.EmitAssignment(Variable(commandResultVariable), commandExpression(arguments)); } else { tryBlock.EmitCallExpression(commandExpression(arguments)); } if (method.HasVkResult) { tryBlock.EmitIfBlock(StaticCall("SharpVkException", "IsError", Variable(commandResultVariable)), ifBlock => { ifBlock.EmitThrow(StaticCall("SharpVkException", "Create", Variable(commandResultVariable))); }); } }