C ++ and C # oriented code generation tool
I have a collection of applications that are built using a combination of C # and C ++. We have a set of common objects between two languages, and instead of defining them separately in each language, I would rather use a code generation tool. Ideally, such a tool would be FOSS, although this is not an absolute requirement. The objects themselves are relatively simple, although there is inheritance from base classes, implementation of interfaces, containment of other types of objects, and collections of other types of objects.
The target C ++ environment is Visual C ++ 2008.
Does anyone have any recommendations for a tool that can handle such a task?
Sample code:
public class Tax
{
private static Dictionary<string, double> _TaxRates;
public Dictionary<string,double> TaxRates { get { return _TaxRates; } }
}
a source to share
For any code generation problem, I'd have a pretty good look at T4 (text templating functionality introduced in VS.NET 2008).
A good place to start with T4 is ...
You need different templates for C ++ and C # and you will generate code from different metadata.
An alternative is to use the CodeDom API. It 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 are links to SO:
T4 vs. CodeDom vs. Oslo Is it possible to dynamically compile and execute C # code snippets?
a source to share
Google Protobuf may be one of the best solutions available for free.
See page page .
a source to share
... Net classes for emitting source code, such as a GenerateCodeFromCompileUnit
base class method CodeDomProvider
, can be used to emit source code in different languages from a single definition: for example, there CppCodeProvider
and also a CSharpCodeProvider
. This can only be controlled by C ++, but you said "relatively simple".
a source to share