コード例 #1
0
        public static bool Check(this TypeEntity entity, string nameSpace)
        {
            entity.TypeType = FieldType.BaseType;
            if (entity.Type.Value == "void")
            {
                entity.TypeType = FieldType.Void;
            }
            else if (!ProtoParser.BaseType.Contains(entity.Type.Value))
            {
                if (ProtoParser.VectorType.Contains(entity.Type.Value))
                {
                    entity.TypeType = FieldType.Vector;
                    Token result = null;
                    if (!CheckType(entity.TypeParam[0], nameSpace, ref result))
                    {
                        Console.WriteLine(string.Format("{0} => Type {1} not exist!", entity.TypeParam[0], entity.TypeParam[0].Value));
                        return(false);
                    }
                    if (result != null)
                    {
                        AddIncude(entity.Type.FileName, result.FileName);
                    }
                    entity.ParamType.Add(ToFieldType(result));
                }
                else if (ProtoParser.MapType.Contains(entity.Type.Value))
                {
                    entity.TypeType = FieldType.Map;
                    if (!ProtoParser.BaseType.Contains(entity.TypeParam[0].Value))
                    {
                        Console.WriteLine(string.Format("{0} => Map Key must be base type!"), entity.TypeParam[0]);
                        return(false);
                    }
                    entity.ParamType.Add(FieldType.BaseType);
                    Token result = null;
                    if (!CheckType(entity.TypeParam[1], nameSpace, ref result))
                    {
                        Console.WriteLine(string.Format("{0} => Type {1} not exist!", entity.TypeParam[0], entity.TypeParam[0].Value));
                        return(false);
                    }
                    if (result != null)
                    {
                        AddIncude(entity.Type.FileName, result.FileName);
                    }
                    entity.ParamType.Add(ToFieldType(result));
                }
                else
                {
                    Token result = null;
                    if (!CheckType(entity.Type, nameSpace, ref result))
                    {
                        Console.WriteLine(string.Format("{0} => Type {1} not exist!", entity.Type, entity.Type.Value));
                        return(false);
                    }
                    if (result != null)
                    {
                        AddIncude(entity.Type.FileName, result.FileName);
                    }

                    entity.TypeType = ToFieldType(result);
                }
            }
            return(true);
        }