private string BuildEnum(EnumLayout layout, TextWriter writer)
            {
                var enumName        = MakeName(layout.Name + " Value");
                var valueNameCounts = new Dictionary <string, int>();

                writer.WriteLine("{0}public enum {1} : {2}", _indent, enumName, GetTypeName(layout.UnderlyingType));
                writer.WriteLine("{0}{{", _indent);
                SetIndent(_indentLevel + 1);
                var nextValue = 0;

                foreach (var val in layout.Values)
                {
                    if (val.Value == nextValue)
                    {
                        writer.WriteLine("{0}{1},", _indent, MakeName(val.Name, valueNameCounts));
                    }
                    else
                    {
                        writer.WriteLine("{0}{1} = {2},", _indent, MakeName(val.Name, valueNameCounts), val.Value);
                    }
                    nextValue = val.Value + 1;
                }
                SetIndent(_indentLevel - 1);
                writer.WriteLine("{0}}}", _indent);
                return(enumName);
            }
        /*private static void ReadBit(XmlReader reader)
         * {
         *  string name = "Unknown";
         *
         *  if (reader.MoveToAttribute("name"))
         *      name = reader.Value;
         *  if (!reader.MoveToAttribute("index"))
         *      throw new ArgumentException("Bit definitions must have an index." + PositionInfo(reader));
         *  int index = ParseInt(reader.Value);
         *
         *  layout.VisitBit(name, index);
         * }*/

        private void ReadOptions(XmlReader reader, string name, BasicFieldType type)
        {
            XmlReader subtree = reader.ReadSubtree();

            var enumLayout = new EnumLayout(name, type);

            subtree.ReadStartElement();
            while (subtree.ReadToNextSibling("option"))
            {
                enumLayout.Add(ReadOption(subtree));
            }

            _results.Layout.Add(new EnumTagLayoutField(name, enumLayout));
        }
        /*private static void ReadBit(XmlReader reader)
        {
            string name = "Unknown";

            if (reader.MoveToAttribute("name"))
                name = reader.Value;
            if (!reader.MoveToAttribute("index"))
                throw new ArgumentException("Bit definitions must have an index." + PositionInfo(reader));
            int index = ParseInt(reader.Value);

            layout.VisitBit(name, index);
        }*/

        private void ReadOptions(XmlReader reader, string name, BasicFieldType type)
        {
            XmlReader subtree = reader.ReadSubtree();

            var enumLayout = new EnumLayout(name, type);
            subtree.ReadStartElement();
            while (subtree.ReadToNextSibling("option"))
                enumLayout.Add(ReadOption(subtree));

            _results.Layout.Add(new EnumTagLayoutField(name, enumLayout));
        }
 public EnumTagLayoutField(string name, EnumLayout layout)
     : base(name)
 {
     Layout = layout;
 }
 public EnumTagLayoutField(string name, EnumLayout layout)
     : base(name)
 {
     Layout = layout;
 }
 private string BuildEnum(EnumLayout layout, TextWriter writer)
 {
     var enumName = MakeName(layout.Name + " Value");
     var valueNameCounts = new Dictionary<string, int>();
     writer.WriteLine("{0}public enum {1} : {2}", _indent, enumName, GetTypeName(layout.UnderlyingType));
     writer.WriteLine("{0}{{", _indent);
     SetIndent(_indentLevel + 1);
     var nextValue = 0;
     foreach (var val in layout.Values)
     {
         if (val.Value == nextValue)
             writer.WriteLine("{0}{1},", _indent, MakeName(val.Name, valueNameCounts));
         else
             writer.WriteLine("{0}{1} = {2},", _indent, MakeName(val.Name, valueNameCounts), val.Value);
         nextValue = val.Value + 1;
     }
     SetIndent(_indentLevel - 1);
     writer.WriteLine("{0}}}", _indent);
     return enumName;
 }