* 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 = ... }).
This commit is contained in:
the_fiddler 2009-10-09 05:48:10 +00:00
parent 6b436dba39
commit 92de857809
2 changed files with 20 additions and 10 deletions

View file

@ -97,7 +97,7 @@ namespace Bind.ES
public override EnumCollection ReadEnums(StreamReader specFile) public override EnumCollection ReadEnums(StreamReader specFile)
{ {
EnumCollection enums = new EnumCollection(); EnumCollection enums = new EnumCollection();
Enum all = new Enum(Settings.CompleteEnumName); Enum all = new Enum() { Name = Settings.CompleteEnumName };
XPathDocument doc = new XPathDocument(specFile); XPathDocument doc = new XPathDocument(specFile);
XPathNavigator nav = doc.CreateNavigator().SelectSingleNode("/signatures"); XPathNavigator nav = doc.CreateNavigator().SelectSingleNode("/signatures");
@ -105,7 +105,11 @@ namespace Bind.ES
foreach (XPathNavigator node in nav.SelectChildren("enum", String.Empty)) 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)) if (String.IsNullOrEmpty(e.Name))
throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString())); throw new InvalidOperationException(String.Format("Empty name for enum element {0}", node.ToString()));

View file

@ -20,7 +20,7 @@ namespace Bind.Structures
internal static EnumCollection AuxEnums = new EnumCollection(); internal static EnumCollection AuxEnums = new EnumCollection();
static StringBuilder translator = new StringBuilder(); static StringBuilder translator = new StringBuilder();
string _name; string _name, _type;
static bool enumsLoaded; static bool enumsLoaded;
#region Initialize #region Initialize
@ -69,12 +69,8 @@ namespace Bind.Structures
#region Constructors #region Constructors
public Enum() public Enum()
{ }
public Enum(string name)
{ {
Name = name; }
}
#endregion #endregion
@ -96,10 +92,17 @@ namespace Bind.Structures
public string Name public string Name
{ {
get { return _name; } get { return _name ?? ""; }
set { _name = value; } set { _name = value; }
} }
// Typically 'long' or 'int'. Default is 'int'.
public string Type
{
get { return String.IsNullOrEmpty(_type) ? "int" : _type; }
set { _type = value; }
}
#endregion #endregion
#region ConstantCollection #region ConstantCollection
@ -182,7 +185,10 @@ namespace Bind.Structures
if (IsFlagCollection) if (IsFlagCollection)
sb.AppendLine("[Flags]"); sb.AppendLine("[Flags]");
sb.AppendLine("public enum " + Name); sb.Append("public enum ");
sb.Append(Name);
sb.Append(" : ");
sb.AppendLine(Type);
sb.AppendLine("{"); sb.AppendLine("{");
foreach (Constant c in constants) foreach (Constant c in constants)