Example #1
0
        public List <SqlBuildParameter> SigleClassConvert <T>(T obj) where T : class
        {
            List <SqlBuildParameter> builds = new List <SqlBuildParameter>();

            if (obj == null)
            {
                return(builds);
            }
            IEntityMapper mapper      = new StandardMapper();
            BuildColumn   buildColumn = new BuildColumn();

            PropertyInfo[] properties = mapper.GetAllProperty(obj.GetType());
            foreach (var item in properties)
            {
                ColumnInfo itemcolinfo = mapper.GetColumnInfo(obj, item);
                buildColumn.SetProperty(item);
                if (itemcolinfo == null || itemcolinfo.IsNull)
                {
                    continue;
                }
                if (itemcolinfo.IsBaseType)
                {
                    buildColumn.SetBuildParameter(ref builds, obj, itemcolinfo);
                }
            }
            return(builds);
        }
        public List <SqlBuildParameter> BuildParameter <T>(T obj) where T : class, new()
        {
            List <SqlBuildParameter> builds = new List <SqlBuildParameter>();

            if (obj == null)
            {
                return(builds);
            }
            IEntityMapper    mapper          = new StandardMapper();
            IStandardConvert standardConvert = new StandObjectConvert();
            BuildColumn      buildColumn     = new BuildColumn();

            PropertyInfo[] properties = mapper.GetAllProperty(obj.GetType());
            foreach (var item in properties)
            {
                ColumnInfo itemcolinfo = mapper.GetColumnInfo(obj, item);
                buildColumn.SetProperty(item);
                if (itemcolinfo == null || itemcolinfo.IsNull)
                {
                    continue;
                }
                if (itemcolinfo.IsBaseType)
                {
                    buildColumn.SetBuildParameter(ref builds, obj, itemcolinfo);
                }
                if (itemcolinfo.IsClass)
                {
                    object         classobjValue   = buildColumn.GetValue(obj);
                    PropertyInfo[] classproperties = mapper.GetAllProperty(itemcolinfo.ColumnType);
                    foreach (var classitem in classproperties)
                    {
                        ColumnInfo classitemcolinfo = mapper.GetColumnInfo(classobjValue, classitem);
                        buildColumn.SetProperty(classitem);
                        if (classitemcolinfo == null | classitemcolinfo.IsNull)
                        {
                            continue;
                        }
                        if (classitemcolinfo.IsBaseType)
                        {
                            buildColumn.SetBuildParameter(ref builds, classobjValue, classitemcolinfo);
                        }
                        if (classitemcolinfo.IsClass)
                        {
                            builds.AddRange(standardConvert.SigleClassConvert(classitemcolinfo.Value));
                        }
                        if (classitemcolinfo.IsGenric)
                        {
                            builds.AddRange(standardConvert.GenericConvert(classitemcolinfo.Value));
                        }
                    }
                }
                if (itemcolinfo.IsGenric)
                {
                    builds.AddRange(standardConvert.GenericConvert(itemcolinfo.Value));
                }
            }
            return(builds);
        }
Example #3
0
        public List <SqlBuildParameter> GenericConvert <T>(T obj) where T : class, IList
        {
            List <SqlBuildParameter> builds = new List <SqlBuildParameter>();

            if (obj == null)
            {
                return(builds);
            }
            IEntityMapper mapper      = new StandardMapper();
            BuildColumn   buildColumn = new BuildColumn();
            IList         objArray    = obj as IList;

            foreach (var item in objArray)
            {
                TableInfo          tableInfo = mapper.GetTableInfo(item.GetType());
                SqlBuildParameter  param     = SqlBuildParameter.Create(tableInfo.Value);
                List <ColumnBuild> colPrams  = new List <ColumnBuild>();
                //解析类的属性字段
                PropertyInfo[] properties = mapper.GetAllProperty(item.GetType());
                foreach (var property in properties)
                {
                    ColumnInfo colinfo = mapper.GetColumnInfo(item, property);
                    if (colinfo == null || colinfo.IsNull)
                    {
                        continue;
                    }
                    if (colinfo.IsBaseType)
                    {
                        buildColumn.SetProperty(property);
                        colPrams.Add(new ColumnBuild {
                            ColumnName = colinfo.TableNameAs,
                            ColType    = colinfo.ColumnType,
                            Value      = colinfo.Value,
                            DbType     = colinfo.DBType
                        });
                    }
                }
                param.ColumnBuilds = colPrams;
                builds.Add(param);
            }
            return(builds);
        }