From 76dcd00b9fa5690a511743db5c8ff1447b241069 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Fri, 9 Oct 2009 05:48:10 +0000 Subject: [PATCH] * ES/ESGenerator.cs: Set enum Type property. * Structures/Enum.cs: Added enum Type property. Removed Enum(string) constructor in favor of C# 3.0 syntax (new Enum() { Name = ... }). --- Source/Bind/ES/ESGenerator.cs | 8 ++++++-- Source/Bind/Structures/Enum.cs | 22 ++++++++++++++-------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Source/Bind/ES/ESGenerator.cs b/Source/Bind/ES/ESGenerator.cs index e2ebb649..1d43fea5 100644 --- a/Source/Bind/ES/ESGenerator.cs +++ b/Source/Bind/ES/ESGenerator.cs @@ -97,7 +97,7 @@ namespace Bind.ES public override EnumCollection ReadEnums(StreamReader specFile) { EnumCollection enums = new EnumCollection(); - Enum all = new Enum(Settings.CompleteEnumName); + Enum all = new Enum() { Name = Settings.CompleteEnumName }; XPathDocument doc = new XPathDocument(specFile); XPathNavigator nav = doc.CreateNavigator().SelectSingleNode("/signatures"); @@ -105,7 +105,11 @@ namespace Bind.ES foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty)) { - Enum e = new Enum(node.GetAttribute("name", String.Empty)); + Enum e = new Enum() + { + Name = node.GetAttribute("name", String.Empty), + Type = node.GetAttribute("type", String.Empty) + }; if (String.IsNullOrEmpty(e.Name)) throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString())); diff --git a/Source/Bind/Structures/Enum.cs b/Source/Bind/Structures/Enum.cs index 0edf1a67..ef7409eb 100644 --- a/Source/Bind/Structures/Enum.cs +++ b/Source/Bind/Structures/Enum.cs @@ -20,7 +20,7 @@ namespace Bind.Structures internal static EnumCollection AuxEnums = new EnumCollection(); static StringBuilder translator = new StringBuilder(); - string _name; + string _name, _type; static bool enumsLoaded; #region Initialize @@ -69,12 +69,8 @@ namespace Bind.Structures #region Constructors public Enum() - { } - - public Enum(string name) { - Name = name; - } + } #endregion @@ -96,9 +92,16 @@ namespace Bind.Structures public string Name { - get { return _name; } + get { return _name ?? ""; } set { _name = value; } } + + // Typically 'long' or 'int'. Default is 'int'. + public string Type + { + get { return String.IsNullOrEmpty(_type) ? "int" : _type; } + set { _type = value; } + } #endregion @@ -182,7 +185,10 @@ namespace Bind.Structures if (IsFlagCollection) sb.AppendLine("[Flags]"); - sb.AppendLine("public enum " + Name); + sb.Append("public enum "); + sb.Append(Name); + sb.Append(" : "); + sb.AppendLine(Type); sb.AppendLine("{"); foreach (Constant c in constants)