public static JNewAnonymousClassExpression CreateDelegate(JMemberExpression delType, JParameterDeclaration[] prms2, JMemberExpression returnType, JBlock body) { if (prms2 == null) { prms2 = new JParameterDeclaration[0]; } if (returnType == null) { returnType = J.Member("void"); } var ce = NewAnonymousType(delType); var me = new JMethodDeclaration { MethodBody = body, Parameters = prms2.ToList(), Annotations = { new JAnnotationDeclaration { Name = "Override" } }, Type = returnType, Name = "invoke", Modifiers = { IsPublic = true }, }; ce.Declarations.Add(me); return(ce); }
public void VisitMethodDeclaration(JMethodDeclaration node) { VisitEach(node.Annotations); var me = node.MethodDefinition; if (node.CustomHeaderCode != null) { Write(node.CustomHeaderCode); } else { WriteModifiers(node); if (node.TypeParameters.IsNotNullOrEmpty()) { if (IsInReturnTypeParametersDeclaration) { throw new Exception("IsInReturnTypeParametersDeclaration"); } IsInReturnTypeParametersDeclaration = true; Write("<"); VisitEachJoin(node.TypeParameters, WriteComma); Write(">"); Write(" "); IsInReturnTypeParametersDeclaration = false; } if (node.Type != null) { Visit(node.Type); Write(" "); } var name = node.Name; if (name == null) { if (me.IsConstructor) { name = me.DeclaringTypeDefinition.Name; } else { name = me.Name; } } Write(name); Write("("); VisitEachJoin(node.Parameters, WriteComma); Write(")"); if (node.MethodBody == null) { Write(";"); } WriteLine(); } Visit(node.MethodBody); }