I have a set of applications that are being built using a combination of C# and C++. We have a set of shared objects between the two languages, and rather than define each one separately in each language, I would prefer to use a code generation tool. Ideally such a tool would be FOSS, although that's not an absolute requirement. The objects themselves are relatively simple, although there is inheritance from baseclasses, implementation of interfaces, containment of other object types, and collections of other object types.
The C++ target environment is Visual C++ 2008.
Does anyone have any recommendations for a tool that can handle this kind of task?
Example code:
public class Tax
{
private static Dictionary<string, double> _TaxRates;
public Dictionary<string,double> TaxRates { get { return _TaxRates; } }
}
For any code generation problem I'd take a good look at T4 (the text templating functionality that appeared in VS.NET 2008).
A good place to start with T4 is...
http://www.hanselman.com/blog/T4TextTemplateTransformationToolkitCodeGenerationBestKeptVisualStudioSecret.aspx
You would need different templates for C++ and C#, and would drive your code generation from some other metadata.
The alternative is to use the CodeDom API. This has two CodeDomProviders (CppCodeProvider and CSharpCodeProvider) that can target each language.
For more information:
http://msdn.microsoft.com/en-us/library/system.codedom.compiler.aspx
There's a related links on SO:
T4 vs CodeDom vs Oslo Is it possible to dynamically compile and execute C# code fragments?
cog is a code-generation tool that lets you embed code-generation python code in your C++/C# files. Its advantage is that it's really easy to use, especially if you already know python.
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