I’m working on a project where I need to construct instances of .cs files dynamically.
I use interfaces to structure the data, something like this (they do vary)
public interface IMetaClass
{
string ParentName { get; set; }
string Namespace { get; set; }
string ClassName { get; set; }
string FriendlyName { get; set; }
string Description { get; set; }
}
I also have classes that inherit from these interfaces
public class XavierMetaClass : IMetaClass
{
public string ParentName { get; set; }
// ...
}
Example of construct and fill
var cell = new XavierMetaClass
{
ParentName = mc.Parent.Name,
Namespace = mc.Namespace,
ClassName = mc.Name,
FriendlyName = mc.FriendlyName,
Description = mc.Description + "test"
};

What I would like to do is take this and construct a new .cs file with the data stored in the variable above with a result looking something like this.
public class CellPhone : IMetaClass
{
public string ParentName { get { return "CatalogEntry"; } }
public string Namespace { get { return "Mediachase.Commerce.Catalog.User"; } }
public string ClassName { get { return "CellPhone"; } }
public string FriendlyName { get { return "Cell sPhone"; } }
public string Description { get { return "Contains meta data about phone test"; } }
private readonly IMetaClass _metaClass;
public CellPhone()
{
// Noop
}
public CellPhone(IMetaClass metaClass)
{
_metaClass = metaClass;
}
}
Are there any know frameworks of methods to help me achieve this?
Thanks
In short you have a few options.
I have done all three and I would recommend T4 templating, and here is an exhaustive example on how to use it.
http://www.codeproject.com/Articles/269362/Using-T4-Templates-to-generate-custom-strongly-typ
But you need to be willing to dig in and learn it because there is quite a bit to grasp.