Beispiel #1
0
 public DefFieldBase(DefTypeBase host, Field f, int idOffset)
 {
     HostType = host;
     Id       = f.Id + idOffset;
     Name     = f.Name;
     Type     = f.Type;
 }
Beispiel #2
0
        public void AddType(DefTypeBase type)
        {
            string fullName = type.FullName;

            if (Types.ContainsKey(fullName))
            {
                throw new Exception($"type:{fullName} duplicate");
            }
            Types.Add(fullName, type);
        }
Beispiel #3
0
 public DefFieldBase(DefTypeBase host, Field f, int idOffset)
 {
     HostType             = host;
     Id                   = f.Id + idOffset;
     AutoId               = Id;
     Name                 = f.Name;
     Type                 = f.Type;
     Comment              = f.Comment;
     Tags                 = DefUtil.ParseAttrs(f.Tags);
     IgnoreNameValidation = f.IgnoreNameValidation;
 }
Beispiel #4
0
        public static void CompileFields <T>(DefTypeBase hostType, List <T> fields, bool verifyId) where T : DefFieldBase
        {
            if (verifyId)
            {
                var ids = new HashSet <int>();
                foreach (var f in fields)
                {
                    if (f.Id == 0)
                    {
                        throw new Exception($"type:{hostType.FullName} field:{f.Name} id can't be 0");
                    }
                    if (!ids.Add(f.Id))
                    {
                        throw new Exception($"type:{hostType.FullName} field:{f.Name} id:{f.Id} duplicate");
                    }
                }
            }

            var names = new HashSet <string>();

            foreach (var f in fields)
            {
                var fname = f.Name;
                if (fname.Length == 0)
                {
                    throw new Exception($"type:{hostType.FullName} field id:{f.Id} name can't be empty");
                }
                if (!names.Add(fname))
                {
                    throw new Exception($"type:{hostType.FullName} field:{fname} duplicate");
                }
                if (TypeUtil.ToCsStyleName(fname) == hostType.Name)
                {
                    throw new Exception($"type:{hostType.FullName} 字段:{fname} 生成的c#字段名与类型名相同,会引起编译错误");
                }
            }

            foreach (var f in fields)
            {
                f.Compile();
            }
        }