public ExpressionSyntax TranslateCustomParameter(ParameterInfo p, CoroutineSpecialVariableAttribute attribute) { var parameterType = p.ParameterType.GenerateTypeHandle(IterationContext.Stencil); var attributeType = attribute.GetType(); ExpressionSyntax expr; var ext = ModelUtility.ExtensionMethodCache <CoroutineParameterTranslator> .GetExtensionMethod( attributeType, FilterMethods, KeySelector); if (ext != null) { var translator = new CoroutineParameterTranslator { Translator = m_Translator }; expr = (ExpressionSyntax)ext.Invoke(null, new object[] { translator, attribute }); } else { string errorMessage = $"Unable to translate MoveNext parameter: [{attributeType.Name}] {p.ParameterType.Name} {p.Name}"; expr = LiteralExpression(SyntaxKind.DefaultLiteralExpression, Token(TriviaList(), SyntaxKind.DefaultKeyword, TriviaList(Comment("/* " + errorMessage + " */")))); Debug.LogError(errorMessage); } return(GetCachedValue(p.Name, expr, parameterType)); }
// Translator for Coroutine MoveNext Parameters have to follow this exact signature // the last parameter being your custom Attribute inheriting from CoroutineSpecialVariableAttribute public static ExpressionSyntax GetInternalVariable(this CoroutineParameterTranslator _, CoroutineInternalVariableAttribute attr) { switch (attr.Variable) { case CoroutineInternalVariable.DeltaTime: return(MemberAccessExpression( SyntaxKind.SimpleMemberAccessExpression, IdentifierName(nameof(Time)), IdentifierName(nameof(Time.deltaTime)))); default: throw new ArgumentOutOfRangeException(); } }