Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static JNewAnonymousClassExpression CreateActionOrFunc(JBlock body, JParameterDeclaration[] prms, JMemberExpression retType, NProject2 project)
        {
            if (prms == null)
            {
                prms = new JParameterDeclaration[0];
            }
            var argTypes    = prms.Select(t => t.Type).ToList();
            var delTypeName = "system.Action";
            var netTypeName = "System.Action";

            if (retType != null)
            {
                delTypeName = "system.Func";
                netTypeName = "System.Func";
                argTypes.Add(retType);
            }
            if (prms.Length > 0)
            {
                delTypeName += prms.Length;
            }
            var delType = CreateTypeRef(delTypeName, argTypes.ToArray());

            if (argTypes.Count > 0)
            {
                netTypeName += "`" + argTypes.Count;
            }
            delType.TypeRef = project.FindType(netTypeName);
            return(CreateDelegate(delType, prms, retType, body));
        }
Exemplo n.º 3
0
        public void VisitParameterDeclaration(JParameterDeclaration node)
        {
            var prm = node.Parameter;

            if (prm != null && prm.Attributes.FirstOrDefault(t => t.AttributeType.Name == "FinalAttribute") != null)
            {
                Write("final ");
            }
            Visit(node.Type);
            Write(" ");
            Write(node.Name);
        }