Ejemplo n.º 1
0
        public static void GenerateEnums(JToken entity, string rootFilePath, string group, string entityName, Compilation compilationContainer)
        {
            var enums = entity["fields"].Where(f => f["enum_reference"] != null);

            // namespace will be common to all enums
            var enumNamespace = UsingKeys.ENUMS;

            foreach (var anEnum in enums)
            {
                var values = new List <EnumItem>()
                {
                    new EnumItem
                    {
                        EnumValue = "UNKNOWN_ENUM_VALUE_RECEIVED",
                    },
                };

                var name = anEnum["enum_reference"].GetStringValue().ToPascal().Replace("Enum", "");
                anEnum["enum"].Values <string>().ToList().ForEach(v =>
                {
                    values.Add(new EnumItem
                    {
                        EnumValue = v.ToUpper().Replace("-", "_"),
                        ApiValue  = v,
                    });
                });

                var filePath = $"{rootFilePath}/{group}/{entityName}/{name}.cs";

                var enumContainer = new EnumContainer
                {
                    Name      = name,
                    Namespace = enumNamespace,
                    Values    = values,
                    FilePath  = filePath,
                };

                enumContainer.AddModifier(nameof(Modifiers.PUBLIC), Modifiers.PUBLIC);

                compilationContainer.AddEnum(name, enumContainer);
            }
        }