Exemplo n.º 1
0
        public override void Compile()
        {
            var FullName           = this.FullName;
            HashSet <string> names = new HashSet <string>();

            foreach (var item in Items)
            {
                if (item.Name.Length == 0)
                {
                    throw new Exception($"{FullName} 常量字段名不能为空");
                }
                if (!names.Add(item.Name))
                {
                    throw new Exception($"{FullName} 字段名:{item.Name} 重复");
                }
                if ((item.CType = AssemblyBase.CreateType(Namespace, item.Type)) == null)
                {
                    throw new Exception($"{FullName} type:{item.Type} 类型不存在");
                }
                if (!item.CType.TryParseFrom(item.Value))
                {
                    throw new Exception($"{FullName} value:{item.Value} 不是合法的 type:{item.Type} 类型值");
                }
            }
        }
Exemplo n.º 2
0
        public virtual void Compile()
        {
            if (Id < 0 || Id > 256)
            {
                throw new Exception($"type:'{HostType.FullName}' field:'{Name}' id:{Id} 超出范围");
            }
            if (!IgnoreNameValidation && !TypeUtil.IsValidName(Name))
            {
                throw new Exception($"type:'{HostType.FullName}' field name:'{Name}' is reserved");
            }

            try
            {
                CType = AssemblyBase.CreateType(HostType.Namespace, Type);
            }
            catch (Exception e)
            {
                throw new Exception($"type:'{HostType.FullName}' field:'{Name}' type:'{Type}' is invalid", e);
            }

            //if (IsNullable && (CType.IsCollection || (CType is TBean)))
            //{
            //    throw new Exception($"type:{HostType.FullName} field:{Name} type:{Type} is collection or bean. not support nullable");
            //}

            switch (CType)
            {
            case TArray t:
            {
                if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0)
                {
                    throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean");
                }
                break;
            }

            case TList t:
            {
                if (t.ElementType is TBean e && !e.IsDynamic && e.Bean.HierarchyFields.Count == 0)
                {
                    throw new Exception($"container element type:'{e.Bean.FullName}' can't be empty bean");
                }
                break;
            }
            }
        }