Exemplo n.º 1
0
 public static JNewAnonymousClassExpression CreateAction(JBlock body, NProject2 project)
 {
     return(CreateActionOrFunc(body, null, null, project));
 }
Exemplo n.º 2
0
 public static JNewAnonymousClassExpression CreateFunc(JMemberExpression retType, JBlock body, NProject2 project)
 {
     return(CreateActionOrFunc(body, null, retType, project));
 }
Exemplo n.º 3
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));
        }