Beispiel #1
0
        public void VerifyDefine()
        {
            if (!Util.MatchIdentifier(Name))
            {
                Error("命名不合法:" + Name);
            }
            if (!IsConst(_fullName))
            {
                Error("常量仅支持基础类型(bool,int,long,float,string,enum):" + Name);
            }
            switch (FullName)
            {
            case Setting.BOOL:
                if (!bool.TryParse(_value, out bool b))
                {
                    Error("值与类型不匹配:" + Name);
                }
                break;

            case Setting.INT:
                if (!int.TryParse(_value, out int i))
                {
                    Error("值与类型不匹配:" + Name);
                }
                break;

            case Setting.LONG:
                if (!long.TryParse(_value, out long l))
                {
                    Error("值与类型不匹配:" + Name);
                }
                break;

            case Setting.FLOAT:
                if (!float.TryParse(_value, out float f))
                {
                    Error("值与类型不匹配:" + Name);
                }
                break;

            default:
                if (EnumWrap.IsEnum(_fullName) && !EnumWrap.Enums[_fullName].ContainItem(Value))
                {
                    Error("值与类型不匹配:" + Name);
                }
                break;
            }
            var git = _groups.GetEnumerator();

            while (git.MoveNext())
            {
                if (!GroupWrap.IsGroup(git.Current))
                {
                    Error("未知 Group:" + git.Current);
                }
            }
        }
Beispiel #2
0
        public void VerifyDefine()
        {
            try
            {
                string inhert = Inherit;
                while (!inhert.IsEmpty())
                {
                    var cls = Get(inhert);
                    if (cls == null)
                    {
                        Error("未知父类" + inhert);
                    }
                    if (!cls.HasChild(_fullName))
                    {
                        cls._children.Add(_fullName);
                    }

                    inhert = cls.Inherit;
                }

                if (!Inherit.IsEmpty() && !IsClass(Inherit))
                {
                    Error("未知父类" + Inherit);
                }
                else
                {
                    HashSet <string> hash = new HashSet <string>();
                    for (int i = 0; i < _consts.Count; i++)
                    {
                        string name = _consts[i].Name;
                        if (!hash.Contains(name))
                        {
                            hash.Add(name);
                        }
                        else
                        {
                            Error("Const命名重复:" + name);
                        }
                        _consts[i].VerifyDefine();
                    }
                    for (int i = 0; i < _fields.Count; i++)
                    {
                        string name = _fields[i].Name;
                        if (!hash.Contains(name))
                        {
                            hash.Add(name);
                        }
                        else
                        {
                            Error("Field命名重复:" + name);
                        }
                        _fields[i].VerifyDefine();
                    }
                }

                var git = _groups.GetEnumerator();
                while (git.MoveNext())
                {
                    if (!GroupWrap.IsGroup(git.Current))
                    {
                        Error("未定义 Group:" + git.Current);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Beispiel #3
0
        public void VerifyDefine()
        {
            CheckType(1);
            if (!Util.MatchIdentifier(Name))
            {
                Error("命名不合法:" + Name);
            }
            string type = OriginalType;

            if (!IsRaw && !IsClass && !IsEnum)
            {
                if (IsContainer)
                {
                    if (type == "list")
                    {
                        CheckType(2);
                        string itemType = _types[1];
                        if (!IsRawOrEnumOrClass(itemType))
                        {
                            Error("list的 item类型不存在或者不是raw,enum,class类型:" + itemType);
                        }
                    }
                    else if (type == "dict")
                    {
                        CheckType(3);
                        string key = _types[1];
                        if (!Setting.RawTypes.Contains(key) && !EnumWrap.IsEnum(key))
                        {
                            Error("非法的dict key类型:" + key);
                        }
                        string value = _types[2];
                        if (!IsRawOrEnumOrClass(value))
                        {
                            Error("非法的dict value类型:" + value);
                        }
                    }
                }
                else
                {
                    Error("未知类型:" + type);
                }
            }

            var git = _groups.GetEnumerator();

            while (git.MoveNext())
            {
                if (!GroupWrap.IsGroup(git.Current))
                {
                    Error("未知 Group:" + git.Current);
                }
            }

            //验证检查规则
            if (_checkers != null)
            {
                var errorCheckers = new List <Checker>();
                var checkers      = _checkers;
                for (int k = 0; k < checkers.Count; k++)
                {
                    if (!checkers[k].VerifyRule())
                    {
                        errorCheckers.Add(checkers[k]);
                    }
                }
                for (int i = 0; i < errorCheckers.Count; i++)
                {
                    _checkers.Remove(errorCheckers[i]);
                }
            }
        }