Search code examples
c#coding-styleproject-organization

Format to include data in C# code


I have a program that uses tables of hard-coded values. E.g.

    public static readonly IDictionary<SpecBuild, BuildInfo> Builds = new Dictionary<SpecBuild, BuildInfo> {
            { SpecBuild.WarriorArms,
                    new BuildInfo {
                            Class = Class.Warrior,
                            Name = "Arms",
                            Role = Role.Melee
                    }
                    },
            { SpecBuild.WarriorFury,
                    new BuildInfo {
                            Class = Class.Warrior,
                            Name = "Fury",
                            Role = Role.Melee
                    }
                    },
            { SpecBuild.WarriorProtection,
                    new BuildInfo {
                            Class = Class.Warrior,
                            Name = "Protection",
                            Role = Role.Tank
                    }
                    }, ...

This data seldom changes, so I am fine with hard-coding it. The problem is that it is hard to read this data, and formatting doesn't work because Resharper reformats it differently.

Ideally I would want a special format file with a custom VS2010 viewer that would present this info as a table and either generate a C# code for those table as part of compilation process, or maybe even compile it directly into MSIL (CLR).

I am looking for a turnkey solution, the problem is not severe enough to warrant any extra development.


Solution

  • Resharper lets me exclude files by extension, so I name my files *.data.cs, format data as I want it, and resharper won't reformat it.