code-generation

CodeDom and collection initializers

家住魔仙堡 提交于 2019-12-03 20:12:48
Is there a way to generate a dictionary initializer using the C# CodeDom? Are those supported at all? I would like to have: private IDictionary<string, string> map = new Dictionary<string, string> { { "Name", "Value" }, ... }; This is not possible using the CodeDom constructs. They were not updated for collection initializers. LukeH has an excellent blog post on the subject of 3.5 features and the CodeDom http://blogs.msdn.com/b/lukeh/archive/2007/07/11/c-3-0-and-codedom.aspx You can do it but its possibly the worst nightmare ever.. Here is how I am doing it currently. (Updated my answer to

Code generators vs. ORMs vs. Stored Procedures

限于喜欢 提交于 2019-12-03 18:50:57
问题 In what domains do each of these software architectures shine or fail? Which key requirements would prompt you to choose one over the other? Please assume that you have developers available who can do good object oriented code as well as good database development. Also, please avoid holy wars :) all three technologies have pros and cons, I'm interested in where is most appropriate to use which. 回答1: Every one of these tools provides differing layers of abstraction, along with differing points

Compile/Execute XAML during program runtime

拜拜、爱过 提交于 2019-12-03 18:14:00
问题 I would like to create an WPF Application which retrieves XAML Code from a Database and displays the retrieved code. Lets say the database return the following code: <Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"> <Grid x:Name="mainGrid"> <Button Content="test case 1" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment=

Generating PHP code (from Parser Tokens)

流过昼夜 提交于 2019-12-03 17:37:11
问题 Is there any available solution for (re-)generating PHP code from the Parser Tokens returned by token_get_all? Other solutions for generating PHP code are welcome as well, preferably with the associated lexer/parser (if any). 回答1: If I'm not mistaken http://pear.php.net/package/PHP_Beautifier uses token_get_all() and then rewrites the stream. It uses heaps of methods like t_else and t_close_brace to output each token. Maybe you can hijack this for simplicity. 回答2: From my comment: Does anyone

Create hash from string and int

為{幸葍}努か 提交于 2019-12-03 17:05:03
问题 I remember eclipse and idea have this template to automatically create an object's hashCode based on its attributes. One of the strategies if a number and a string is used is something like this. return stringValue.hashCode() + intValue * 32; Ooor something like that. I don't have nor eclipse or idea at hand and I would like to create such function. EDIT Based on the answers I create this mini-class class StringInt { private final String s; private final int i; static StringInt valueOf(

Generating sources by running a project's java class in Maven

試著忘記壹切 提交于 2019-12-03 16:58:55
问题 I'm converting a largish Ant build to Maven. As part of the Ant build, we have several steps which created Java classes by invoking one of the project's classes, simplified as: javac SomeGenerator.java java SomeGenerator generated # generate classes in generated/ javac generated/*.java I've split each generator in its own Maven module, but I have the problem of not being able to run the generator since it's not yet compiled in the generate-sources phase. I've tried something similar to

What is model driven development good for?

我的未来我决定 提交于 2019-12-03 16:58:43
Microsoft, of Cairo fame, is working on Oslo, a new modeling platform . Bob Muglia, Senior Vice President of Microsoft Server & Tools Business, states that the benefits of modeling have always been clear. In simple, practical terms, what are the clear benefits that Oslo bestows upon its users? In theory, there are a few benefits: The people with the business knowledge can create the software models so you're less likely to lose anything in translation. When non-technical shareholders create models, it forces them to "think like a developer". They see that what they considered obvious and easy

Generating LLVM Code from Java

雨燕双飞 提交于 2019-12-03 16:27:20
问题 I want to use the LLVM code generation Framework from Java. I.e., I do not want to compile Java code into LLVM. I simply want an LLVM library for code generation that I can call from Java. The usual LLVM library is C, so I cannot use it. Are there any Java ports? If no, what would be the easiest way to do it anyway? Wrap the API into JNI? 回答1: A quick search for llvm java api bindings turned out several projects that seem like a good fit: LLVM-J JLLVM LAJ All of those libraries use JNI to

Are code generators bad?

断了今生、忘了曾经 提交于 2019-12-03 15:44:40
问题 I use MyGeneration along with nHibernate to create the basic POCO objects and XML mapping files. I have heard some people say they think code generators are not a good idea. What is the current best thinking? Is it just that code generation is bad when it generates thousands of lines of not understandable code? 回答1: Code generated by a code-generator should not (as a generalisation) be used in a situation where it is subsequently edited by human intervention. Some systems such the wizards on

Simple CRUD Generation

断了今生、忘了曾经 提交于 2019-12-03 14:35:01
This is what I have: An entity-relational schema, modelled for Doctrine 2.0 (in PHP); The generated database, on a MySQL server. This is what I want: A very basic CRUD web-interface to the database, that allows me to (you guessed it!) create, read, update and delete records, with extra credit for implementing CRUD operations on entities and relations instead of records. Now, I'm terrible at writing web applications myself (read: I'm lazy). Are there any options to generate a CRUD web application from a MySQL database, or from a set of Doctrine entities? I'd be willing to stop using PHP (and