Ejemplo n.º 1
0
        public void DefineEnum(AST.Enum type)
        {
            Namespace(type.Namespace, false, () =>
            {
                WriteXmlDocumentation(type.XmlDoc);
                Line($"public enum {type.Name} : {type.UnderlyingType.Name}");
                Block(() =>
                {
                    List(CodeListStyle.MultiLine, () =>
                    {
                        bool canPresume = true;

                        for (int i = 0; i < type.Entries.Count; i++)
                        {
                            var entry = type.Entries[i];

                            canPresume &= i == entry.Value;

                            WriteXmlDocumentation(entry.XmlDoc);
                            if (canPresume)
                            {
                                Code(type.Entries[i].Name);
                            }
                            else
                            {
                                Code($"{type.Entries[i].Name} = {type.Entries[i].Value}");
                            }

                            NextListItem();
                        }
                    });
                });
            });
        }
Ejemplo n.º 2
0
        public void GenerateEnum(AST.Enum type)
        {
            Spacer();
            WriteXmlDocumentation(type.XmlDoc);
            Line("enum class {0} : {1}", type.Name, TypeRef(type.UnderlyingType));
            Block(() =>
            {
                List(CodeListStyle.MultiLine, () =>
                {
                    int len    = type.Entries.Max(entry => entry.Name.Length) + 1;
                    bool broke = false;

                    for (int i = 0; i < type.Entries.Count; i++)
                    {
                        var entry = type.Entries[i];
                        broke     = broke || entry.Value != i;

                        WriteXmlDocumentation(entry.XmlDoc);
                        if (broke)
                        {
                            ListItem("{0,-" + len + "} = 0x{1:X8}", entry.Name, entry.Value);
                        }
                        else
                        {
                            ListItem(entry.Name);
                        }
                    }
                });
            }, ";");
        }