public static IEnumerable <SyntaxNode> BuildFunctionCall(this RoslynEcsTranslator translator, FunctionCallNodeModel call, IPortModel portModel) { if (call.MethodInfo == null) { yield break; } var instance = translator.BuildArgumentList(call, out var argumentList); var typeArgumentList = new List <TypeSyntax>(); if (call.MethodInfo.IsGenericMethod) { typeArgumentList.AddRange(call.TypeArguments.Select(t => IdentifierName(t.GetMetadata(translator.Stencil).Name))); } TypeArgumentListSyntax typeArgList = null; if (typeArgumentList.Any()) { typeArgList = TypeArgumentList(SingletonSeparatedList(typeArgumentList.First())); } var method = RoslynBuilder.MethodInvocation(call.MethodInfo.Name, call.MethodInfo, instance, argumentList, typeArgList); if (method is ExpressionSyntax exp && call.MethodInfo is MethodInfo mi && mi.ReturnType != typeof(void) && call.MethodInfo.DeclaringType.Namespace.StartsWith("UnityEngine")) { var key = call.DeclaringType.Name(translator.Stencil).ToPascalCase() + call.Title.ToPascalCase(); yield return(translator.context.GetCachedValue(key, exp, mi.ReturnType.GenerateTypeHandle(translator.Stencil))); }
public static IEnumerable <SyntaxNode> BuildFunctionRefCall(this RoslynEcsTranslator translator, FunctionRefCallNodeModel call, IPortModel portModel) { if (!call.Function) { yield break; } ExpressionSyntax instance = translator.BuildArgumentList(call, out var argumentList); if (!call.Function.IsInstanceMethod) { instance = IdentifierName(((VSGraphModel)call.Function.GraphModel).TypeName); } var invocationExpressionSyntax = instance == null || instance is LiteralExpressionSyntax && instance.IsKind(SyntaxKind.NullLiteralExpression) ? InvocationExpression(IdentifierName(call.Function.CodeTitle)) : InvocationExpression( MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, instance, IdentifierName(call.Function.CodeTitle))); invocationExpressionSyntax = invocationExpressionSyntax.WithArgumentList( ArgumentList(SeparatedList(argumentList))); if (portModel == null) { yield return(ExpressionStatement(invocationExpressionSyntax).NormalizeWhitespace()); } else { yield return(invocationExpressionSyntax.NormalizeWhitespace()); } }