Format for including data in C # code

I have a program that uses hardcoded tables. For instance.

    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 rarely changes, so I'm fine-tuned. The problem is that reading this data is difficult, and formatting does not work, because Resharper reformatts it differently.

Ideally, I would like to get a special format file with a custom VS2010 representation that would represent this information in a table and generate C # code for this table as part of the compilation process, or perhaps even compile it directly into MSIL (CLR).

I am looking for a turnkey solution, the problem is not so serious as to guarantee additional development.

+3
source share
4

Resharper , *.data.cs, ​​ , , resharper .

0

( , ) (, resx). . , , JSON JavaScriptSerializer JSON.NET. , - ( , ). XML, , .

, .

+2

VS2010

:

  • DSL
  • VS2010, DSL
  • ( MSBuild)
  • VS- .

, , , .

, , . :

  • Resharper, ( , ).
  • (, XML, JSON...), VS . ( ).

, # 1 () , . # 2 - ( XAML ).

0

T4

void SpecBuild(string spec, string @class, string name, string role)
{
    Write(string.Format("{{ SpecBuild.{0}, " +
                        "new BuildInfo {{ " +
                        "Class = Class.{1}, " +
                        "Name = @\"{2}\", " +
                        "Role = Role.{3} " +
                        "}} " +
                        "}},",
                        spec,
                        @class,
                        name.Replace("\"", "\"\""),
                        role));
}

//        SpecBuild            Class      Name          Role
//        -------------------- ---------- ------------- -------
SpecBuild("WarriorArms",       "Warrior", "Arms",       "Melee");
SpecBuild("WarriorFury",       "Warrior", "Fury",       "Melee");
SpecBuild("WarriorProtection", "Warrior", "Protection", "Melee");
//        -------------------- ---------- ------------- -------
0

All Articles