예제 #1
0
        public static bool Check(this EnumEntity entity, string nameSpace)
        {
            if (entity.Name == null)
            {
                return(false);
            }
            for (int i = 0; i < entity.Fields.Count; ++i)
            {
                var field = entity.Fields[i];
                if (field.Name.Value.IndexOf("MSG_ID_") == 0 ||
                    field.Name.Value.IndexOf("RPC_") == 0)
                {
                    if (field.Value == null)
                    {
                        Console.WriteLine(string.Format("{0} => Msg or RPC ID must have value, like: MSG_ID_XXX = 12345, or RPC_service_func=123", field.Name));
                        return(false);
                    }
                    MsgIDEntity idEntity = new MsgIDEntity()
                    {
                        FieldToken = field.Name,
                        ValueToken = field.Value,
                        EnumToken  = entity.Name,
                    };
                    if (!AddMsgIdEntity(nameSpace, idEntity))
                    {
                        return(false);
                    }
                }
                for (int j = i + 1; j < entity.Fields.Count; ++j)
                {
                    if (field.Name.Value == entity.Fields[j].Name.Value)
                    {
                        Console.WriteLine(string.Format("{0} => Enum field name repeated", field.Name));
                        return(false);
                    }
                }
            }
            var token = FindName(nameSpace, entity.Name);

            if (token != null)
            {
                Console.WriteLine(string.Format("{0} => Enum name has exist in {1}", entity.Name, token));
                return(false);
            }
            return(true);
        }
예제 #2
0
 public static EnumEntity ParseEnumEntity(TokenIterator it)
 {
     if (EnumMatch.Match(it))
     {
         EnumEntity entity = new EnumEntity();
         if (VarNameMatch.Match(it, ref entity.Name) && OpeningbraceMatch.Match(it))
         {
             while (true)
             {
                 if (CloseingbraceMatch.Match(it))
                 {
                     break;
                 }
                 var field = ParseEnumField(it);
                 entity.Fields.Add(field);
             }
             return(entity);
         }
         throw new Exception(ItToError(it));
     }
     return(null);
 }