Questions tagged [code-generation]

Topics related to the generation of code as the output of an application, instead of directly writing code by a programmer.

3642 questions
56
votes
5 answers

Is there a way to generate multiple files/classes with intellij code/file templates?

I like intellij's code/file templates, they are working really well for me for single files but it would be great to be able to create multiple files/classes at once. I did find this question but since it has been a few years since I was hoping that…
Trevor Gowing
  • 2,236
  • 22
  • 25
55
votes
4 answers

zip(list1, list2) in Jinja2?

I'm doing code generation in Jinja2 and I frequently want to iterate through two lists together (i.e. variables names and types), is there a simple way to do this or do I need to just pass a pre-zipped list? I was unable to find such a function in…
John Salvatier
  • 3,077
  • 4
  • 26
  • 31
53
votes
3 answers

Reflection.Emit vs CodeDOM

What are some pros/cons for using the Reflection.Emit library versus CodeDOM for dynamically generating code at runtime? I am trying to generate some (relatively complicated) dynamic classes in a system based on metadata available at runtime in XML…
LBushkin
  • 129,300
  • 32
  • 216
  • 265
51
votes
8 answers

C# Source Generator - warning CS8032: An instance of analyzer cannot be created

I'm trying to build a Source Generator. Right now, just the most basic static method that returns "Hello World". The generator project builds, but the generated code is not available, the debugger never starts, and the build output shows CSC :…
farlee2121
  • 2,959
  • 4
  • 29
  • 41
49
votes
2 answers

Get Project or Relative Directory with T4

How can I get a reference to the directory of the visual studio project or solution or the directory of the t4 template from within a t4 template? I have a template that concatenates a number of files together which are located relative to the…
Blake Taylor
  • 9,217
  • 5
  • 38
  • 41
48
votes
8 answers

How can I serialize an object to C# object initializer code?

I'm looking to take an in-memory object (or JSON serialization of an object) and emit C# code to produce an equivalent object. This would be useful for pulling known-good examples from a repository to use as starting points in unit tests. We have…
Matthew Nichols
  • 4,866
  • 4
  • 41
  • 48
47
votes
8 answers

'CompanyName.Foo' is a 'namespace' but is used like a 'type'

Restatement of the question I'm resurrecting this question because I just ran into this error again today, and I'm still utterly confused why the C# compiler bothers to check for collisions between namespaces and types in contexts where it makes no…
devuxer
  • 41,681
  • 47
  • 180
  • 292
43
votes
3 answers

Generate POCO classes in different project to the project with Entity Framework model

I'm trying to use the Repository Pattern with EF4 using VS2010. To this end I am using POCO code generation by right clicking on the entity model designer and clicking Add code generation item. I then select the POCO template and get my…
Max
  • 1,543
  • 2
  • 16
  • 31
43
votes
4 answers

How can I see the assembly code that is generated by a gcc (any flavor) compiler for a C/C++ program?

I am trying to optimize a lot of multiplications and pointer arithmetics and would like to see what the compiler does underneath when I put in optimization flags. --Edit-- How to restrict it to a specific function or a code block? --Edit_2-- How…
vehomzzz
  • 42,832
  • 72
  • 186
  • 216
40
votes
6 answers

How do I execute ruby template files (ERB) without a web server from command line?

I need ERB (Ruby's templating system) for templating of non-HTML files. (Instead, I want to use it for source files such as .java, .cs, ...) How do I "execute" Ruby templates from command line?
ivan_ivanovich_ivanoff
  • 19,113
  • 27
  • 81
  • 100
39
votes
9 answers

Generate JPA 2 Entities from existing Database

How can I generate JPA2 compliant @Entity from existing Databases?. I found this: Question Still its not clear if JBoss will generate compliant JPA2 and also I would like to know if there is a vendor independent way to do this.
will824
  • 2,203
  • 4
  • 27
  • 29
39
votes
1 answer

Is there any way to have functions in basic T4 templates?

By basic T4 template, I mean not using T4 Toolkit or any of the add-ins. My T4 is getting a little complicated, but I'd like to keep in self-contained for now. Is there a way have functions in your T4 template, without referencing external…
Patrick Karcher
  • 22,995
  • 5
  • 52
  • 66
38
votes
0 answers

How to use RoboPOJOGenerator to automatically generate model class from Json in Android Studio

I will share a way to generate class from Json in Android. Generate Java and Kotlin POJO files from JSON: GSON, AutoValue, Logan Square, FastJSON, Jackson, Moshi, empty annotations template. Supports: primitive types, multiple inner…
Thientvse
  • 1,753
  • 1
  • 14
  • 23
38
votes
8 answers

How can I create database tables from XSD files?

I have a set of XSDs from which I generate data access classes, stored procedures and more. What I don't have is a way to generate database table from these - is there a tool that will generate the DDL statements for me? This is not the same as…
Oded
  • 489,969
  • 99
  • 883
  • 1,009
37
votes
1 answer

What is CGLIB in Spring Framework?

What is CGLIB and how it is related to Spring? Do we have to define usage of CGLIB explicitly when using Spring Framework?
Punter Vicky
  • 15,954
  • 56
  • 188
  • 315