code-generation

Tool to generate interface implementation by delegation ?

I often need to implement an interface by delegating the implementation to a member of my class. This task is quite tedious because, even though Visual Studio generates stubs for the interface methods, I still have to write the code to delegate the implementation. It doesn't require much thinking, so it could probably be automated by a c...

two TypeBuilders calling eachother illegal?

Hey, I'm generating (using System.Reflection.Emit) two types: call them foo, bar. The catch is, foo instantiates and calls bar, and bar uses foo. All works fine when I create bar, but when I then start generating foo, I get typeloadexception saying that type foo could not be found. It happens (probably, as the error was vague) when I t...

Mixed types in a logic tree in c#

I have an UGLY logic tree that I'm looking at ways replace with some code generated from a table. It branches based on several thing: the length of a List<AbstractType> the actual types in the list a flags enum My basic idea is to build some kind of decision tree from by input table. For the list length and flags that's easy (a switc...

Can the controller code generation template be changed?

In Visual Studio when you add a new controller to your MVC application some macro creates a file with methods like: // // GET: /Thing/Details/5 public ActionResult Details(int id) { return View(); } I want my methods to look like: /// <example>GET: /Thing/Details/XXX...</example> public ActionResult Details(Guid id) { return...

Difference between code generated using a template function and a normal function

I have a vector containing large number of elements. Now I want to write a small function which counts the number of even or odd elements in the vector. Since performance is a major concern I don't want to put an if statement inside the loop. So I wrote two small functions like: long long countOdd(const std::vector<int>& v) { long l...

Generate database schema from NHibernate mapping

Is it possible to generate the database schema from the Nhibernate mappings DLL? My requirements is for MySQL. If so, how do I do that? Are there tools/scripts for this? Open source/freeware tools? Additionally, can I use these tools to insert/update datasets to the database? ...

Is there a code generation tool that accepts Excel files as input?

I'm looking to generate some C# code based on Excel data. Basically the Excel sheet contains definitions of functions that need to be generated in C#. My current experience with code generation is mainly with ORM's. But now the "input" is Excel data. I'm asking this to prevent me from re-inventing the wheel. Reading data from Excel is ...

Class generation from database schema

I've dug around through previously asked questions and have had no luck finding a duplicate. I would love to generate basic entity classes in .Net from a DB2 schema (using the iSeries OLEDB provider). Is there any simple way to do this? I've looked into MyGeneration and CodeSmith and it just seems like there must be an easier way. ...

T4 Templates - SubSonic 3 - Running at Build Time

How do you get the SubSonic 3 T4 templates to rerun prior to building in VS2008? I don't have to continually "Run Custom Tool" on each one? ...

Are there differences between EnvDTE or CodeDom when generating Code

I have the requirement to generate and read some CS classes with a DSL, I have adopted one method for reading the CS files using EnvDTE and my colleague has used CodeDom to produce the CS files. Is it just sugar or is there a big difference between... codeClass.AddFunction("DoSomething", vsCMFunction.vsCMFunctionFunction, "bool"); an...

Which code generation tools do you use?

If you use one of course, which one? MyGeneration T4 UML Transformation Tool (precise which one) ... All others not listed above since there are so many ...

StringTemplate for runtime code gen?

Hi, I am working on a project that generates code at runtime based on meta-model. I've used vb.net xml literals for this, but today I ran accross StringTemplate project. Has anybody successfully used this library in C# project. ...

Programmatically Format Generated CodeDom Code

How can I make sure the CS generated from code like the following is formatted nicely, i.e as if we pressed CTRL-K D? It is C# We are doing something along the lines of: CodeMemberMethod membMethod = new CodeMemberMethod(); membMethod.Attributes = MemberAttributes.Static | MemberAttributes.Public; membMethod.Ret...

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 template. I need to get a reference to there absolute location through a relative means. Hard ...

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 to let gcc generate a less verbose assembly-code? ...

Is there any #pragma or similar directive for generated C# code to match template code line numbers to C# line number?

I have a templating system that looks similar to old-style ASP code. I run this through a class that rewrites the entire thing into C# source code, compiles, and finally executes it. What I'm wondering is if there is some kind of #pragma-like directive I can sprinkle the generated C# code with that will make compile errors match the lin...

Dynamic compilation for performance

Hello everyone, I have an idea of how I can improve the performance with dynamic code generation, but I'm not sure which is the best way to approach this problem. Suppose I have a class class Calculator { int Value1; int Value2; //.......... int ValueN; void DoCalc() { if (Value1 > 0) { DoValue1RelatedStuf...

Python generating Python

Ok, I have a group of objects which I am creating a class for that I want to store each object as its own text file. I would really like to store it as a Python class definition which subclasses the main class I am creating. So, I did some poking around and found a Python Code Generator on effbot.org. I did some experimenting with it and...

Linux automated code formatting (PHP, JavaScript, HTML, CSS, MySQL)

I am seeking a Linux or PHP program to automate code formatting. Optimally it would handle many languages, but the priority is (highest first): PHP, JavaScript, HTML, CSS and MySQL. Comparability is nice, but not the most important feature. Context / use: automation via Subversion post-commit. I'm working with teams and want to alway...

[phpunit] automated test generation?

hi all currently im writing a test for a report function the more functionality the project gets the more reports need to be written in my case reports get a few 'search' paramters and limitations like number of rows or such now my question: anyone knows how to generate test cases automatically for a function which has a well known se...