I liked visual studio 2010 resx framework, I would like to have same functionality but with custom columns. I thought about following solution:
Example:
Xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<field name="x" loggerLevel="Verbose"/>
<field name="y" loggerLevel="Details"/>
</resources>
Translated to code:
class Resources{
public readonly Field x = new Field(LoggerLevel.Verbose);
public readonly Field y = new Field(LoggerLevel.Details);
}
The question is am I over killing here? Is there any simpler solution to achieve my goal?
EDIT: Fixed the xml.
A simple T4 template may be sufficient, and T4 is already built in MSVS. Add your XML to the project (make sure that it is valid, your current XML example is not valid), and add T4 template to the same project directory as your XML file. Edit namespace name and XML file name as you like (sample code uses "T4Example" for namespace and "Example.xml" for input file name).
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core.dll" #>
<#@ assembly name="System.Xml.dll" #>
<#@ assembly name="System.Xml.Linq.dll" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>
namespace T4Example
{
class Fields
{
<#
string stringsDir = Path.GetDirectoryName(this.Host.TemplateFile);
string reswFile = Path.Combine(stringsDir, @"Example.xml");
var doc = XDocument.Load(reswFile);
var data = doc.Element("xml")
.Element("fields")
.Elements("field")
.Select(i => Tuple.Create(
i.Attribute("name").Value,
i.Attribute("loggerLevel").Value));
foreach(var tuple in data)
{#>
public readonly Field <#=tuple.Item1#> = new Field(LoggerLevel.<#=tuple.Item2#>);
<# }#>
}
}