From 745dae3dbe1c4e421ed5b0bf9d99e3d0584f9926 Mon Sep 17 00:00:00 2001 From: the_fiddler Date: Tue, 12 Oct 2010 16:41:21 +0000 Subject: [PATCH] Added support for token overrides. --- Source/Bind/ES/ESGenerator.cs | 47 +++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/Source/Bind/ES/ESGenerator.cs b/Source/Bind/ES/ESGenerator.cs index 6369410e..fe2df5ab 100644 --- a/Source/Bind/ES/ESGenerator.cs +++ b/Source/Bind/ES/ESGenerator.cs @@ -140,10 +140,46 @@ namespace Bind.ES foreach (XPathNavigator param in node.SelectChildren(XPathNodeType.Element)) { - Constant c = new Constant(param.GetAttribute("name", String.Empty), param.GetAttribute("value", String.Empty)); + Constant c = null; + switch (param.Name) + { + case "token": + c = new Constant + { + Name = param.GetAttribute("name", String.Empty), + Value = param.GetAttribute("value", String.Empty) + }; + break; + + case "use": + c = new Constant + { + Name = param.GetAttribute("token", String.Empty), + Reference = param.GetAttribute("enum", String.Empty), + Value = param.GetAttribute("token", String.Empty), + }; + break; + + default: + throw new NotSupportedException(); + } Utilities.Merge(all, c); - try { e.ConstantCollection.Add(c.Name, c); } - catch (ArgumentException ex) { Console.WriteLine("[Warning] Failed to add constant {0} to enum {1}: {2}", c.Name, e.Name, ex.Message); } + try + { + if (!e.ConstantCollection.ContainsKey(c.Name)) + { + e.ConstantCollection.Add(c.Name, c); + } + else if (e.ConstantCollection[c.Name].Value != c.Value) + { + Console.WriteLine("[Warning] Conflicting token {0}.{1} with value {2} != {3}", + e.Name, c.Name, e.ConstantCollection[c.Name].Value, c.Value); + } + } + catch (ArgumentException ex) + { + Console.WriteLine("[Warning] Failed to add constant {0} to enum {1}: {2}", c.Name, e.Name, ex.Message); + } } Utilities.Merge(enums, e); @@ -152,8 +188,9 @@ namespace Bind.ES } Utilities.Merge(enums, all); - enums.Translate(overrides); - return enums; + return new EnumProcessor(overrides).Process(enums); + //enums.Translate(overrides); + //return enums; } } }