Ejemplo n.º 1
0
        /// <summary>
        /// Add an enum to the service for the given enum type annotated with the KRPCEnum attribute.
        /// Returns the name of the enumeration.
        /// </summary>
        public string AddEnum(Type enumType)
        {
            TypeUtils.ValidateKRPCEnum(enumType);
            var name = enumType.Name;

            if (Enumerations.ContainsKey(name))
            {
                throw new ServiceException("Service " + Name + " contains duplicate enumerations " + name);
            }
            var values = new List <EnumerationValueSignature> ();

            foreach (FieldInfo field in enumType.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                values.Add(new EnumerationValueSignature(Name, name, field.Name, (int)field.GetRawConstantValue(), field.GetDocumentation()));
            }
            Enumerations [enumType.Name] = new EnumerationSignature(Name, name, values, enumType.GetDocumentation());
            return(enumType.Name);
        }