I'm sure this is a very weird requirement, but here goes.
We have some customer configuration code that is represented by C# classes that we compile into a class library. Creating these configuration classes is currently monkey work that I'd like to assign to someone other than a developer. We're therefore building a "Configurator" website that a business analyst can use to generate valid C# classes by filling in a form with the relevant options selected.
What is the best way to generate a C# class from a template in an MVC website? Note that I'm not talking here about dynamically generating and executing a class at runtime: we're essentially generating a text file that just happens to contain C# code that will be included in a totally different project.
This is proving to be a very difficult topic to google properly! Options that have come up so far...
Any ideas on how best to approach this?
As requested, here's an example of the output class/file. Values in here override values set in a base class with customer-specific labels, validation, etc. This is how we customise our product for customers.
public class AreaRiskTemplate: AreaRiskTemplateBase
{
public override string EntityName { get { return "risk"; } }
public override string EntityNamePlural { get { return "risks"; } }
public override string EntityNameArticle { get { return "a"; } }
public override string CGovItemRefPrefix { get { return "R"; } }
public override void SetFieldDefinitions()
{
FieldDefinitions.Level1.IsImplemented = true;
FieldDefinitions.Level1.Label = "Category";
FieldDefinitions.Level1.IsVisibleInGrid = true;
FieldDefinitions.Level2.IsImplemented = true;
FieldDefinitions.Level2.Label = "Team";
FieldDefinitions.Level2.IsVisibleInGrid = true;
FieldDefinitions.Description.IsImplemented = true;
FieldDefinitions.Description.Label = "Description";
FieldDefinitions.Description.IsVisibleInGrid = true;
}
public override ModelStateDictionary Validate()
{
var msd = new ModelStateDictionary();
// add template-specific validation here
msd.Merge(base.Validate());
return msd;
}
public override List<string> Level1Options
{
get
{
return new List<string>
{
"Organisational",
"Financial",
"Operational",
"External",
"IT"
};
}
}
}
Update: currently investigating T4 templates at http://msdn.microsoft.com/en-us/library/ee844259(v=vs.100).aspx (thanks to comments below). Looks promising.
C-Free is a free IDE software for PC developed by Program Arts Software.
I suggest avoiding the website, and instead simply going with CodeSmith. You can design CodeSmith scripts so that it will ask for information and then generate the required code. Seems like a lot less work, although you do have to buy CodeSmith.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With