Example #1
0
        public static void RemoveCommonPrefix(Definitions.EnumDefinition @enum)
        {
            if (@enum.Items.Count == 0)
            {
                return;
            }
            var fieldNames  = @enum.Items.Select(item => NamedTool.SplitWord(item.Name)).ToArray();
            int commonCount = 0;

            while (true)
            {
                if (commonCount >= fieldNames[0].Length)
                {
                    break;
                }
                if (fieldNames.Skip(1).Any(names => commonCount >= names.Length || names[commonCount] != fieldNames[0][commonCount]))
                {
                    break;
                }
                commonCount++;
            }
            for (int i = 0; i < @enum.Items.Count; i++)
            {
                var csharpName = NamedTool.ToCamelNamed(fieldNames[i].Skip(commonCount));
                if (char.IsDigit(csharpName[0]))
                {
                    csharpName = "_" + csharpName;
                }
                @enum.Items[i].CSharpName = csharpName;
            }
        }
Example #2
0
 protected virtual void RenameStructField(Definitions.StructDefinition @struct, Definitions.StructField field)
 {
     field.CSharpName = NamedTool.ToCamelNamed(field.Name);
 }