diff --git a/Source/Bind/Structures/Constant.cs b/Source/Bind/Structures/Constant.cs index 0c6b1626..79d785ea 100644 --- a/Source/Bind/Structures/Constant.cs +++ b/Source/Bind/Structures/Constant.cs @@ -7,6 +7,7 @@ using System; using System.Diagnostics; using System.Globalization; +using System.Linq; using System.Text; namespace Bind.Structures @@ -174,7 +175,10 @@ namespace Bind.Structures translator.Remove(0, translator.Length); // Translate the constant's name to match .Net naming conventions - if ((Settings.Compatibility & Settings.Legacy.NoAdvancedEnumProcessing) == Settings.Legacy.None) + bool name_is_all_caps = s.AsEnumerable().All(c => Char.IsLetter(c) ? Char.IsUpper(c) : true); + bool name_contains_underscore = s.Contains("_"); + if ((Settings.Compatibility & Settings.Legacy.NoAdvancedEnumProcessing) == Settings.Legacy.None && + (name_is_all_caps || name_contains_underscore)) { bool next_char_uppercase = true; bool is_after_digit = false; diff --git a/Source/Bind/Structures/Enum.cs b/Source/Bind/Structures/Enum.cs index ef7409eb..cde8cb1b 100644 --- a/Source/Bind/Structures/Enum.cs +++ b/Source/Bind/Structures/Enum.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Text; using System.Xml.XPath; @@ -118,6 +119,7 @@ namespace Bind.Structures #region TranslateName + // Translate the constant's name to match .Net naming conventions public static string TranslateName(string name) { if (String.IsNullOrEmpty(name)) @@ -128,13 +130,12 @@ namespace Bind.Structures translator.Remove(0, translator.Length); // Trick to avoid allocating a new StringBuilder. - // Translate the constant's name to match .Net naming conventions if ((Settings.Compatibility & Settings.Legacy.NoAdvancedEnumProcessing) == Settings.Legacy.None) { - bool is_after_underscore_or_number = true; // Detect if we just passed a '_' or a number and make the next char - // uppercase. - bool is_previous_uppercase = false; // Detect if previous character was uppercase, and turn - // the current one to lowercase. + // Detect if we just passed a '_' or a number and make the next char uppercase. + bool is_after_underscore_or_number = true; + // Detect if previous character was uppercase, and turn the current one to lowercase. + bool is_previous_uppercase = false; foreach (char c in name) { @@ -145,10 +146,12 @@ namespace Bind.Structures { if (Char.IsDigit(c)) is_after_underscore_or_number = true; + char_to_add = is_after_underscore_or_number ? Char.ToUpper(c) : is_previous_uppercase ? Char.ToLower(c) : c; - is_previous_uppercase = Char.IsUpper(c); translator.Append(char_to_add); + + is_previous_uppercase = Char.IsUpper(c); is_after_underscore_or_number = false; } }