Beispiel #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;
            }
        }
Beispiel #2
0
 protected virtual void VisitEnum(Definitions.EnumDefinition @enum)
 {
     if (enumFlagsRegex.IsMatch(@enum.Name))
     {
         @enum.IsFlags = true;
     }
     foreach (var item in @enum.Items)
     {
         VisitEnumItem(@enum, item);
     }
 }
 public void WriteEnum(Definitions.EnumDefinition @enum)
 {
     WriteSummary(@enum);
     if (@enum.IsFlags)
     {
         Writer.WriteLine("[Flags]");
     }
     using (BeginBlock($"public enum {@enum.CSharpName} : {@enum.TypeName} ")) {
         foreach (var item in @enum.Items)
         {
             WriteSummary(item);
             Writer.WriteLine($"{item.CSharpName} = {item.Value},");
         }
     }
 }
Beispiel #4
0
 protected virtual void RenameEnum(Definitions.EnumDefinition @enum)
 {
     if (@enum.CSharpName != null)
     {
         return;
     }
     @enum.CSharpName = @enum.Name;
     if (CanRemoveCommonPrefix)
     {
         RemoveCommonPrefix(@enum);
     }
     foreach (var item in @enum.Items)
     {
         RenameEnumItem(@enum, item);
     }
 }
Beispiel #5
0
 protected virtual void VisitEnumItem(Definitions.EnumDefinition @enum, Definitions.EnumItem item)
 {
 }
Beispiel #6
0
 protected virtual void RenameEnumItem(Definitions.EnumDefinition @enum, Definitions.EnumItem item)
 {
 }