Topics related to the generation of code as the output of an application, instead of directly writing code by a programmer.
Questions tagged [code-generation]
3642 questions
25
votes
3 answers
T4 Get Current Working Directory of Solution
I am using T4 in Visual Studio 2010, and I want to iterate over the files in my solution, however I have found that T4 source generation works in a kind of a sandbox, and the current working directory is inside of the Visual Studio 10 directory in…

aceinthehole
- 5,122
- 11
- 38
- 54
25
votes
6 answers
Generate Delete Statement From Foreign Key Relationships in SQL 2008?
Is it possible via script/tool to generate a delete statement based on the tables fk relations.
i.e. I have the table: DelMe(ID) and there are 30 tables with fk references to its ID that I need to delete first, is there some tool/script that I can…

Element
- 3,981
- 7
- 42
- 51
25
votes
3 answers
Best design for generating code from an AST?
I'm working on a pretty complex DSL that I want to compile down into a few high level languages. The whole process has been a learning experience. The compiler is written in java.
I was wondering if anyone knew a best practice for the design of…

Sam Washburn
- 1,817
- 3
- 25
- 43
25
votes
8 answers
Generate setters that return self in Eclipse
I'd like to have my setters so that I can chain them like:
myPojo.setX(x).setY(y);
Usually I generate setters with Eclipse but unfortunately code template for setters allows me to change only the body of the setter, not the signature.
What would be…

vertti
- 7,539
- 4
- 51
- 81
24
votes
3 answers
Can I get an XML AST dump of C/C++ code with clang without using the compiler?
I managed to compile successfully clang for windows with cmake and visual studio 10. I would like to get an XML file as AST representation of the source code. There is one option that provides the result with clang with gcc under linux (ubuntu) but…

jdehaan
- 19,700
- 6
- 57
- 97
24
votes
8 answers
generate PHP classes from XSD?
Is there in the world analogues of JavaBeans or JAXB for PHP?
Is it possible to generate PHP classes from XML schema?
It's common practice to publish API's as XSD schemas. Java and C# guys can get advantage of this by generating classes right from…

Qwerty
- 1,732
- 1
- 13
- 18
24
votes
4 answers
How do I determine if a column is in the primary key of its table? (SQL Server)
I am currently using...
select Table_Name, Column_name, data_type, is_Nullable
from information_Schema.Columns
...to determine information about columns in a given database for the purposes of generating a DataAccess Layer.
From where can I…

Rory Becker
- 15,551
- 16
- 69
- 94
24
votes
3 answers
Code replacement with an annotation processor
I'm trying to write an annotation processor to insert methods and fields on a class... and the documentation is so sparse. I'm not getting far and I don't know if I'm approaching it correctly.
The processing environment provides a Filer object which…

Boann
- 48,794
- 16
- 117
- 146
23
votes
4 answers
How can i get enum to contain a dash (-)?
I'm generating business objects from this schema using Enterprise Architect.
The schema has the following enumeration specification:
…

capdragon
- 14,565
- 24
- 107
- 153
23
votes
3 answers
Looking for a standalone, command line, code generator script
I'm looking for a library or command line script that will allow me to create custom templates that I can generate from the command line. The ruby on rails scaffolding generator is almost identical to what I am trying to do. I would even prefer that…

Andrew
- 227,796
- 193
- 515
- 708
23
votes
6 answers
How can I add my attributes to Code-Generated Linq2Sql classes properties?
I would like to add attributes to Linq 2 Sql classes properties. Such as this Column is browsable in the UI or ReadOnly in the UI and so far.
I've thought about using templates, anybody knows how to use it? or something different?
Generally…

ArielBH
- 1,991
- 3
- 22
- 38
23
votes
5 answers
How to make Xcode automatically conform to a protocol
When I use a prototype table view, I always have to conform to the protocol TableViewDataSource. I always forget what methods I need to implement, so I have to look at the source of the protocol every time. This is really time consuming.
I think…

Sweeper
- 213,210
- 22
- 193
- 313
23
votes
3 answers
suppress warning for generated c# code
I have turned on "Treat warnings as errors" for my VS project which mean that I get errors for missing documentation (nice reminder for this particular project).
However, part of the code is generated by a custom tool which does not insert xml…

soren.enemaerke
- 4,770
- 5
- 53
- 80
23
votes
7 answers
Creating T4 templates at runtime (build-time)?
We are building an inhouse application which needs to generate HTML files for upload into eBay listings. We are looking to use a template engine to generate the HTML files based on database and static fields that we have pre-defined. The template…

Amberite
- 1,379
- 3
- 14
- 27
23
votes
4 answers
Using Roslyn to parse/transform/generate code: am I aiming too high, or too low?
(What I'm trying to do is work around the Application.Settings/MVVM problem by generating an interface and wrapper class from the vs-generated settings file.)
What I'd like to do is:
Parse a class declaration from file
Generate an interface…

Benjol
- 63,995
- 54
- 186
- 268