Ejemplo n.º 1
0
        private void ReadEnum(Type type)
        {
            EnumConfig config = _project.Enums.FirstOrDefault(p => p.Name == type.Name) ?? new EnumConfig
            {
                Name = type.Name
            };

            _project.Add(config);
            GetInfo(config, type);
            foreach (var field in type.GetFields(BindingFlags.Static | BindingFlags.Public))
            {
                var col = config.Items.FirstOrDefault(p => p.Name == field.Name);
                if (col == null)
                {
                    config.Add(col = new EnumItem
                    {
                        Name  = field.Name,
                        Value = Convert.ToInt64(field.GetValue(null)).ToString()
                    });
                }
                GetInfo(col, type, field);
            }
        }
Ejemplo n.º 2
0
        public static void ReadPropertyEnum(PropertyConfig column)
        {
            var line = column.Description?.Trim(CoderBase.NoneLanguageChar) ?? "";

            StringBuilder sb          = new StringBuilder();
            StringBuilder caption     = new StringBuilder();
            bool          preIsNumber = false;
            bool          startEnum   = false;
            EnumConfig    ec          = new EnumConfig
            {
                Name        = column.Parent.Name.ToUWord() + column.Name.ToUWord(),
                Description = column.Description,
                Caption     = column.Caption,
                Items       = new ConfigCollection <EnumItem>()
            };
            EnumItem ei = new EnumItem();

            foreach (var c in line)
            {
                if (c >= '0' && c <= '9')
                {
                    if (!preIsNumber)
                    {
                        if (!startEnum)
                        {
                            caption.Append(sb);
                        }
                        else if (sb.Length > 0)
                        {
                            new List <string>().Add(sb.ToString());
                            ei.Caption = sb.ToString();
                        }
                        sb        = new StringBuilder();
                        startEnum = true;
                    }
                    preIsNumber = true;
                }
                else
                {
                    if (preIsNumber)
                    {
                        if (sb.Length > 0)
                        {
                            ei = new EnumItem
                            {
                                Value = sb.ToString()
                            };
                            ec.Add(ei);
                            sb = new StringBuilder();
                        }
                    }
                    preIsNumber = false;
                }
                sb.Append(c);
            }

            if (!startEnum)
            {
                return;
            }
            if (sb.Length > 0)
            {
                if (preIsNumber)
                {
                    ec.Add(new EnumItem
                    {
                        Value = sb.ToString()
                    });
                }
                else
                {
                    ei.Caption = sb.ToString();
                }
            }

            if (ec.Items.Count > 0)
            {
                ec.Option.ReferenceKey = column.Option.Key;
                column.EnumConfig      = ec;
                column.CustomType      = ec.Name;
                column.Description     = line;
                foreach (var item in ec.Items)
                {
                    if (string.IsNullOrEmpty(item.Caption))
                    {
                        column.EnumConfig = null;
                        column.CustomType = null;
                        return;
                    }
                    var arr = item.Caption.Trim(CoderBase.NoneNameChar).Split(CoderBase.NoneNameChar, StringSplitOptions.RemoveEmptyEntries);
                    if (arr.Length == 0)
                    {
                        column.EnumConfig = null;
                        column.CustomType = null;
                        return;
                    }
                    item.Caption = arr[0].MulitReplace2("", "表示", "代表", "是", "为");
                    item.Name    = item.Name;
                }
                if (caption.Length > 0)
                {
                    column.Caption = caption.ToString();
                }
            }
            else
            {
                column.EnumConfig = null;
                column.CustomType = null;
            }
        }