Beispiel #1
0
        public static Setting CombineSetting(Setting exists, Setting newsetting)
        {
            if (exists == null)
            {
                return(newsetting);
            }

            foreach (var item in newsetting.Columns)
            {
                var find = exists.Columns.FirstOrDefault(o => o.Name.ToLower() == item.Name.ToLower());

                if (find != null)
                {
                    find.DataType  = item.DataType;
                    find.Length    = item.Length;
                    find.isComplex = item.isComplex;
                    // TODO: if change datatype from fixed len = 0, we need to reorganize.
                }
                else
                {
                    var type = Helper.TypeHelper.GetType(item.DataType);
                    if (type != null)
                    {
                        exists.AppendColumn(item.Name, type, item.Length);
                    }
                }
            }


            return(exists);
        }
Beispiel #2
0
        public static List <TableColumn> GetTypeColumns(object obj)
        {
            var setting = new Setting();

            if (obj is System.Collections.IDictionary)
            {
                var idict = obj as System.Collections.IDictionary;

                foreach (var item in idict.Keys)
                {
                    var value = idict[item];

                    if (value != null)
                    {
                        var valuetype = value.GetType();
                        int len       = 0;
                        if (valuetype == typeof(string))
                        {
                            if (value.ToString().Length > (Constants.DefaultColLen - 300))
                            {
                                len = int.MaxValue;
                            }
                            else
                            {
                                len = Constants.DefaultColLen;
                            }
                        }
                        else
                        {
                            len = SettingHelper.GetColumnLen(valuetype, 0);
                        }
                        setting.AppendColumn(item.ToString(), valuetype, len);
                    }
                }
            }

            else if (obj is IDictionary <string, object> )
            {
                var idict = obj as IDictionary <string, object>;

                foreach (var item in idict)
                {
                    if (item.Value != null)
                    {
                        var valuetype = item.Value.GetType();
                        int len       = 0;
                        if (valuetype == typeof(string))
                        {
                            if (item.Value.ToString().Length > (Constants.DefaultColLen - 300))
                            {
                                len = int.MaxValue;
                            }
                            else
                            {
                                len = Constants.DefaultColLen;
                            }
                        }
                        else
                        {
                            len = SettingHelper.GetColumnLen(valuetype, 0);
                        }
                        setting.AppendColumn(item.Key, valuetype, len);
                    }
                }
            }

            else
            {
                var type = obj.GetType();

                var AllProperties = Helper.TypeHelper.GetPublicPropertyOrFields(type);

                foreach (var item in AllProperties)
                {
                    setting.AppendColumn(item.Key, item.Value, 0);
                }
            }

            return(setting.Columns.ToList());
        }