示例#1
0
        CSParameterList MapParameters(ICollection <ParameterDefinition> methodParameters)
        {
            CSParameterList parameters = new CSParameterList();

            foreach (var methodParameter in methodParameters)
            {
                var parameterType = MapType(methodParameter.ParameterType);
                var parameterKind = ToParameterKind(methodParameter);
                var parameter     = new CSParameter(parameterType, methodParameter.Name, parameterKind);
                parameters.Add(parameter);
            }

            return(parameters);
        }
 static bool IsUnusualParameter(Entity entity, CSParameter parameter)
 {
     // check to see if an entity is either an objc struct or enum
     return(entity != null && (entity.IsObjCStruct || entity.IsObjCEnum) && parameter.ParameterKind == CSParameterKind.Ref);
 }
示例#3
0
        protected Result[] PreGenerateCode(JObject data)
        {
            CSParameter entry = new CSParameter();

            DataSet ds = RunProcedureDataSet(data, "vdp_get_page_for_gen_client", "sys");

            if (ds.Tables.Count >= 2)
            {
                entry.page                  = new Page();
                entry.page.Author           = CurrentUser.RealName;
                entry.page.id               = (int)ds.Tables[0].Rows[0]["id"];
                entry.page.template_id      = (int)ds.Tables[0].Rows[0]["template_id"];
                entry.page.page_name        = (string)ds.Tables[0].Rows[0]["page_name"];
                entry.page.description      = (string)ds.Tables[0].Rows[0]["description"];
                entry.page.parent_menu_code = (string)ds.Tables[0].Rows[0]["parent_menu_code"];
                entry.page.page_name_text   = (string)ds.Tables[0].Rows[0]["page_name_text"];
                entry.page.controller_area  = (string)ds.Tables[0].Rows[0]["controller_area"];
                entry.page.controller       = (string)ds.Tables[0].Rows[0]["controller"];


                entry.page_detail = new List <PageDetail>();
                foreach (DataRow r in ds.Tables[1].Rows)
                {
                    PageDetail tmpPageDetail = new PageDetail();
                    tmpPageDetail.id                  = (int)r["id"];
                    tmpPageDetail.area                = (string)r["area"];
                    tmpPageDetail.table_name          = (string)r["table_name"];
                    tmpPageDetail.module_id           = (int)r["module_id"];
                    tmpPageDetail.comments            = (string)r["comments"];
                    tmpPageDetail.name_text           = (string)r["name_text"];
                    tmpPageDetail.class_name          = (string)r["class_name"];;
                    tmpPageDetail.RelatedChildenTable = (string)r["related_childen_table"];
                    tmpPageDetail.table_description   = "";
                    entry.page_detail.Add(tmpPageDetail);
                    data["page_detail_id"] = tmpPageDetail.id;
                    DataSet ds2 = RunProcedureDataSet(data, "vdp_get_page_detail_for_gen_client", "sys");
                    int     w   = 0;

                    ColumnSet cs;
                    tmpPageDetail.columns = new List <ColumnSet>();
                    foreach (DataRow r2 in ds2.Tables[0].Rows)
                    {
                        cs            = new ColumnSet();
                        cs.isInsert   = r2["is_insert"].ToString() == "0" ? false : true;
                        cs.isShow     = r2["is_show"].ToString() == "0" ? false : true;
                        cs.isUpdate   = r2["is_update"].ToString() == "0" ? false : true;
                        cs.isRequired = r2["is_required"].ToString() == "0" ? false : true;
                        cs.isWhere    = r2["is_where"].ToString() == "0" ? false : true;
                        tmpPageDetail.table_description = (string)r2["table_description"];
                        if (r2["size"].ToString() == "")
                        {
                            w = 0;
                        }
                        else
                        {
                            w = int.Parse(r2["length"].ToString()) * 10;
                        }
                        if (w > 500)
                        {
                            w = 500;
                        }
                        cs.width        = w;
                        cs.data         = (string)r2["data"];
                        cs.valid        = (string)r2["valid"];
                        cs.staticValue  = (string)r2["static_value"];
                        cs.FlagIdentity = int.Parse(r2["flag_identity"].ToString());
                        cs.FlagPrimary  = int.Parse(r2["flag_primary"].ToString());// (int)r2["flag_primary"];
                        cs.ColumnName   = (string)r2["column_name"];
                        cs.Type         = (string)r2["type"];
                        if (r2["size"].ToString() == "")
                        {
                            cs.Size = 0;
                        }
                        else
                        {
                            string tmpstr = r2["size"].ToString();
                            if (tmpstr.Length >= 5)
                            {
                                tmpstr = "50000";
                            }
                            if (int.Parse(tmpstr) > 6000)
                            {
                                cs.Size = 6000;
                            }
                            else
                            {
                                cs.Size = Int16.Parse(tmpstr);//(Int16)r2["size"];
                            }
                        }
                        if (r2["length"].ToString() == "")
                        {
                            cs.Length = 0;
                        }
                        else
                        {
                            cs.Length = int.Parse(r2["length"].ToString());// (int)r2["length"];
                        }
                        cs.htmlType           = (string)r2["html_type"];
                        cs.ColumnCaption      = (string)r2["column_caption"];
                        cs.ColumnDescription  = (string)r2["column_description"];
                        cs.RelatedParentTable = (string)r2["related_table"];
                        cs.staticValue        = (string)r2["static_value"];
                        cs.PrimaryField       = (string)r2["primary_field"];
                        if (r2["is_identity"].ToString() == "1")
                        {
                            cs.IsIdentity = true;
                        }
                        else
                        {
                            cs.IsIdentity = false;
                        }
                        tmpPageDetail.columns.Add(cs);
                    }
                }
            }



            Result[] r3 = mycs.CreateCode(JSToken, entry);
            return(r3);
        }
        public CSDelegateTypeDecl CompileToDelegateDeclaration(FunctionDeclaration func, CSUsingPackages packs,
                                                               string mangledName, string delegateName, bool objectsAreIntPtrs, CSVisibility vis, bool isSwiftProtocol)
        {
            bool returnIsGeneric = func.IsTypeSpecGeneric(func.ReturnTypeSpec);
            var  args            = typeMap.MapParameterList(func, func.ParameterLists.Last(), objectsAreIntPtrs, true, null, null);

            RemapSwiftClosureRepresensation(args);
            var returnType = returnIsGeneric ? null : typeMap.MapType(func, func.ReturnTypeSpec, objectsAreIntPtrs, true);

            delegateName = delegateName ?? typeMap.SanitizeIdentifier(func.Name);

            args.ForEach(a => AddUsingBlock(packs, a.Type));

            if (returnType != null && !returnIsGeneric)
            {
                AddUsingBlock(packs, returnType);
            }

            CSType csReturnType = returnType == null || returnType.IsVoid ? CSSimpleType.Void : returnType.ToCSType(packs);
            var    csParams     = new CSParameterList();

            for (int i = 0; i < args.Count; i++)
            {
                var         arg          = args [i];
                var         argIsGeneric = func.IsTypeSpecGeneric(func.ParameterLists.Last() [i].TypeSpec);
                CSParameter csParam      = null;
                var         parmType     = func.ParameterLists.Last() [i].TypeSpec;
                if (arg.Type.Entity == EntityType.Tuple || (!argIsGeneric && IsObjCStruct(parmType)))
                {
                    csParam = new CSParameter(CSSimpleType.IntPtr, new CSIdentifier(arg.Name), CSParameterKind.None, null);
                }
                else
                {
                    csParam = new CSParameter(arg.Type.ToCSType(packs), new CSIdentifier(arg.Name),
                                              arg.Type.IsReference ? CSParameterKind.Ref : CSParameterKind.None, null);
                }
                csParams.Add(csParam);
            }

            if (isSwiftProtocol)
            {
                packs.AddIfNotPresent(typeof(SwiftExistentialContainer1));
                csParams.Insert(0, new CSParameter(new CSSimpleType(typeof(SwiftExistentialContainer1)), new CSIdentifier("self"), CSParameterKind.Ref));
            }
            else
            {
                csParams.Insert(0, new CSParameter(CSSimpleType.IntPtr, new CSIdentifier("self")));
            }

            var retvalName = "xam_retval";
            var retvalID   = new CSIdentifier(retvalName);

            if (func.HasThrows || returnIsGeneric || !returnType.IsVoid)               // && func.Signature.ReturnType.IsStruct || func.Signature.ReturnType.IsEnum) {
            {
                if (func.HasThrows)
                {
                    csParams.Insert(0, new CSParameter(CSSimpleType.IntPtr, retvalName, CSParameterKind.None));
                    csReturnType = CSSimpleType.Void;
                }
                else
                {
                    if (!returnIsGeneric)
                    {
                        if (!(func.ReturnTypeSpec is ClosureTypeSpec))
                        {
                            Entity ent = typeMap.GetEntityForTypeSpec(func.ReturnTypeSpec);
                            if (ent == null && !(func.ReturnTypeSpec is ProtocolListTypeSpec))
                            {
                                throw ErrorHelper.CreateError(ReflectorError.kCompilerBase + 8, $"Unable to find entity for class {csReturnType.ToString ()}.");
                            }

                            if (ent != null && (ent.IsStructOrEnum || ent.EntityType == EntityType.Protocol))
                            {
                                csParams.Insert(0, new CSParameter(CSSimpleType.IntPtr, retvalID, CSParameterKind.None));
                                csReturnType = CSSimpleType.Void;
                            }
                            else if (func.ReturnTypeSpec is ProtocolListTypeSpec pl)
                            {
                                csParams.Insert(0, new CSParameter(new CSSimpleType($"SwiftExistentialContainer{pl.Protocols.Count}"), retvalID, CSParameterKind.Ref));
                                csReturnType = CSSimpleType.Void;
                            }
                        }
                    }
                    else
                    {
                        csParams.Insert(0, new CSParameter(CSSimpleType.IntPtr, retvalID, CSParameterKind.None));
                    }
                }
            }

            return(new CSDelegateTypeDecl(vis, csReturnType, new CSIdentifier(delegateName), csParams));
        }
示例#5
0
        protected Result[] PreGenerateCode(JObject data)
        {
            CSParameter entry = new CSParameter();

            DataSet ds = RunProcedureDataSet(data, "vdp_get_page_for_gen_client", "sys");

            if (ds.Tables.Count >= 2)
            {
                entry.page                  = new Page();
                entry.page.Author           = CurrentUser.RealName;
                entry.page.id               = (int)ds.Tables[0].Rows[0]["id"];
                entry.page.template_id      = (int)ds.Tables[0].Rows[0]["template_id"];
                entry.page.page_name        = (string)ds.Tables[0].Rows[0]["page_name"];
                entry.page.description      = (string)ds.Tables[0].Rows[0]["description"];
                entry.page.parent_menu_code = (string)ds.Tables[0].Rows[0]["parent_menu_code"];
                entry.page.page_name_text   = (string)ds.Tables[0].Rows[0]["page_name_text"];
                entry.page.controller_area  = (string)ds.Tables[0].Rows[0]["controller_area"];
                entry.page.controller       = (string)ds.Tables[0].Rows[0]["controller"];


                entry.page_detail = new List <PageDetail>();
                //   ds.Tables[1];

                //  entry.columns = new List<ColumnSet>();
                foreach (DataRow r in ds.Tables[1].Rows)
                {
                    PageDetail tmpPageDetail = new PageDetail();
                    //   tmpPageDetail.columns = new List<ColumnSet>();
                    tmpPageDetail.id                = (int)r["id"];
                    tmpPageDetail.area              = (string)r["area"];
                    tmpPageDetail.table_name        = (string)r["table_name"];
                    tmpPageDetail.module_id         = (int)r["module_id"];
                    tmpPageDetail.comments          = (string)r["comments"];
                    tmpPageDetail.name_text         = (string)r["name_text"];
                    tmpPageDetail.class_name        = (string)r["class_name"];
                    tmpPageDetail.table_description = "";
                    //  tmpPageDetail.edit_flag = (int)r["edit_flag"];
                    entry.page_detail.Add(tmpPageDetail);
                    data["page_detail_id"] = tmpPageDetail.id;
                    DataSet ds2 = RunProcedureDataSet(data, "vdp_get_page_detail_for_gen_client", "sys");
                    int     w   = 0;

                    ColumnSet cs;
                    tmpPageDetail.columns = new List <ColumnSet>();
                    foreach (DataRow r2 in ds2.Tables[0].Rows)
                    {
                        cs            = new ColumnSet();
                        cs.isInsert   = (int)r2["isInsert"] == 0 ? false : true;
                        cs.isShow     = (int)r2["isShow"] == 0 ? false : true;
                        cs.isUpdate   = (int)r2["isUpdate"] == 0 ? false : true;
                        cs.isRequired = (int)r2["isRequired"] == 0 ? false : true;
                        cs.isWhere    = (int)r2["isWhere"] == 0 ? false : true;
                        tmpPageDetail.table_description = (string)r2["TableDescription"];
                        w = (int)r2["Length"] * 10;
                        if (w > 500)
                        {
                            w = 500;
                        }
                        cs.width             = w;
                        cs.data              = (string)r2["data"];
                        cs.valid             = (string)r2["valid"];
                        cs.staticValue       = (string)r2["staticValue"];
                        cs.FlagIdentity      = (int)r2["FlagIdentity"];
                        cs.FlagPrimary       = (int)r2["FlagPrimary"];
                        cs.ColumnName        = (string)r2["ColumnName"];
                        cs.Type              = (string)r2["type"];
                        cs.Size              = (Int16)r2["size"];
                        cs.Length            = (int)r2["length"];
                        cs.htmlType          = (string)r2["htmlType"];
                        cs.ColumnCaption     = (string)r2["ColumnCaption"];
                        cs.ColumnDescription = (string)r2["ColumnDescription"];
                        cs.staticValue       = (string)r2["staticValue"];
                        cs.PrimaryField      = (string)r2["PrimaryField"];
                        if ((int)r2["isIdentity"] == 1)
                        {
                            cs.IsIdentity = true;
                        }
                        else
                        {
                            cs.IsIdentity = false;
                        }
                        tmpPageDetail.columns.Add(cs);
                    }
                }
            }



            //string p2 = Server.MapPath("\\") + "\\templates\\test2.data";

            //FileStream fs3 = new FileStream(p2, FileMode.Create);

            //BinaryFormatter bf = new BinaryFormatter();
            //bf.Serialize(fs3, entry);
            //fs3.Close();


            Result[] r3 = mycs.CreateCode(JSToken, entry);
            return(r3);
        }