public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { if (CommentText.IsNotEmpty()) { writer.WriteComment(CommentText); } var invokeMethod = InvocationCode(method); if (shouldWriteInUsingBlock(method)) { writer.UsingBlock($"{returnActionCode(method)}{invokeMethod}", w => Next?.GenerateCode(method, writer)); } else { writer.Write($"{returnActionCode(method)}{invokeMethod};"); // This is just to make the generated code a little // easier to read if (CommentText.IsNotEmpty()) { writer.BlankLine(); } Next?.GenerateCode(method, writer); } }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { if (CommentText.IsNotEmpty()) { writer.WriteComment(CommentText); } var invokeMethod = invocationCode(); var returnValue = ""; if (IsAsync) { #if NET461 || NET48 if (method.AsyncMode == AsyncMode.AsyncTask) { invokeMethod = invokeMethod + ".ConfigureAwait(false)"; } #endif returnValue = method.AsyncMode == AsyncMode.ReturnFromLastNode ? "return " : "await "; } var isDisposable = false; if (shouldAssignVariableToReturnValue(method)) { #if !NET4x returnValue = ReturnVariable.VariableType.IsValueTuple() ? $"{ReturnVariable.Usage} = {returnValue}" : $"{ReturnVariable.AssignmentUsage} = {returnValue}"; #else returnValue = $"{ReturnVariable.AssignmentUsage} = {returnValue}"; #endif isDisposable = ReturnVariable.VariableType.CanBeCastTo <IDisposable>(); } if (isDisposable && DisposalMode == DisposalMode.UsingBlock) { writer.UsingBlock($"{returnValue}{invokeMethod}", w => Next?.GenerateCode(method, writer)); } else { writer.Write($"{returnValue}{invokeMethod};"); // This is just to make the generated code a little // easier to read if (CommentText.IsNotEmpty()) { writer.BlankLine(); } Next?.GenerateCode(method, writer); } }
public override void GenerateCode(GeneratedMethod method, ISourceWriter writer) { if (CommentText.IsNotEmpty()) { writer.WriteComment(CommentText); } var invokeMethod = invocationCode(); var returnValue = ""; if (IsAsync) { returnValue = method.AsyncMode == AsyncMode.ReturnFromLastNode ? "return " : "await "; } var isDisposable = false; if (shouldAssignVariableToReturnValue(method)) { #if !NET4x returnValue = ReturnVariable.VariableType.IsValueTuple() ? $"{ReturnVariable.Usage} = {returnValue}" : $"var {ReturnVariable.Usage} = {returnValue}"; #else returnValue = $"var {ReturnVariable.Usage} = {returnValue}"; #endif isDisposable = ReturnVariable.VariableType.CanBeCastTo <IDisposable>(); } if (isDisposable && DisposalMode == DisposalMode.UsingBlock) { writer.UsingBlock($"{returnValue}{invokeMethod}", w => Next?.GenerateCode(method, writer)); } else { writer.Write($"{returnValue}{invokeMethod};"); Next?.GenerateCode(method, writer); } }