code-generation

Tool to generate interface implementation by delegation?

萝らか妹 提交于 2019-12-04 16:57:21
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 code generation tool... I'm probably not the first one to think of this, so there must be such a tool already, but I couldn't find anything on Google... Any idea ? EDIT : it seems that ReSharper can do it , but it's pretty expensive... is there a free

Can EF4 generate POCO for me, or do I have to write them myself?

女生的网名这么多〃 提交于 2019-12-04 16:56:55
I've been playing about with the Entity 4 framework lately and it's pretty nifty. I've setup a class called Customer.cs with some properties like Name, Address etc. I also have a class called StoreEntities.cs which binds these back to the database through DbSet. It works fine and I can pull all my customers from the database. The problem is every tutorial I come across on the internet generates their classes by hand. What I mean is, they all say something like "Now I'm going to make a new class called Orders with the following properties" and then proceed to write it out. That might be ok if I

suppress warning for generated c# code

…衆ロ難τιáo~ 提交于 2019-12-04 15:47:11
问题 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 documentation so I'm looking for away to ignore the missing xml documentation for the generated code only, not for the entire project. I have no influence on the actual file generated and cannot really insert anything in the file (as it is regenerated

How to use Brail as a stand-alone general purpose templating engine (like NVelocity)?

六月ゝ 毕业季﹏ 提交于 2019-12-04 14:58:34
I've been using NVelocity as a stand-alone templating engine in my text file generator. The problem with NVelocity is that the macros are quite shaky; pretty much all errors I get are from faulty macro implementation. It would be cool if I could just use some other templating engine, such as Brail. That way I would just write functions that output strings. What's the best way of embedding Brail engine? I would like to just pass it a string containing the template (not reading from disk), and I would like to minimize the number of external dependencies. EDIT: I found the answer myself. Take a

Runtime code generation and compilation

 ̄綄美尐妖づ 提交于 2019-12-04 14:50:53
Say I have this code that uses some input (e.g. a URL path) to determine which method to run, via reflection: // init map.put("/users/*", "viewUser"); map.put("/users", "userIndex"); // later String methodName = map.get(path); Method m = Handler.class.getMethod(methodName, ...); m.invoke(handler, ...); This uses reflection so the performance can be improved. It could be done like this: // init map.put("/users/*", new Runnable() { public void run() { handler.viewUser(); } }); map.put("/users", new Runnable() { public void run() { handler.userIndex(); } }); // later Runnable action = map.get

JAXB Types problem

妖精的绣舞 提交于 2019-12-04 14:06:54
问题 I have an xsd that looks like this (snippet): <xs:complexType name="IDType"> <xs:choice minOccurs="1" maxOccurs="2"> <xs:element name="FileID" minOccurs="0" maxOccurs="1" type="an..35" /> <xs:element name="IDNumber1" minOccurs="0" maxOccurs="1" type="an..35" /> <xs:element name="Number" minOccurs="0" maxOccurs="1" type="an..35" /> <xs:element name="PNumber" minOccurs="0" maxOccurs="1" type="an..35" /> <xs:element name="SS" minOccurs="0" maxOccurs="1" type="an..35" /> <xs:element name="Player"

Do any Java libraries use annotations for code generation?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 13:40:25
问题 Is anyone aware of a library that uses the the techniques (annotations and classworking) described in this article for automatically generating the standard Object methods toString(), equals() and hashcode() for standard java classes? 回答1: Yes, project Lombok does this. See http://projectlombok.org . It not only supports javac, but also Eclipse. So the methods are not in the source code, but are displayed in the outline view. 回答2: I certainly haven't seen this and I'm not really sure what

Is there a Perl script to implement C++ Class get/set member functions?

♀尐吖头ヾ 提交于 2019-12-04 12:44:34
I was reading this morning the book The Pragmatic Programmer Chapter 3 on Basic Tools every programmer should have and they mentioned Code Generation Tools. They mentioned one Perl script for C++ programs which helped automate the process of implementing the get/set() member functions for private data members. Does anyone know about such a script and where to find it? I've been unable to come up with the right google keywords to find it. j_random_hacker Although it doesn't directly answer your question, you may find that generated code is actually unnecessary for managing properties in C++.

CompileAssemblyFromDom throws access denied exception

孤者浪人 提交于 2019-12-04 12:42:28
The code: using (var codeProvider = new CSharpCodeProvider()) { var compilerParameter = new CompilerParameters( _assemblies, assemblyName, false) { GenerateInMemory = true, CompilerOptions = "/optimize" }; var compilerResults = codeProvider.CompileAssemblyFromDom( compilerParameter, templateResults.Select(r => r.GeneratedCode) .ToArray()); } It throws exception: CS1567 Error generating Win32 resource: Access is denied. What does it mean? I get this working. The problem was that assemblyName was file name not path, so I changed assemblyName = Path.Combine(Path.GetTempPath(), assemblyName); And

How to get Hibernate Tools to generate POJOs with toString,equals and hashcode?

余生长醉 提交于 2019-12-04 11:51:42
Hibernate Tools plugin (version 3.2.4) for eclipse Hi all, I'm using the plugin to reverse engineer my POJOs and DAOs from my DB-Schema and for some reason the toString,equals and hashcode methods aren't created in the POJOs. What I'm doing is the following: Create a new JPA project. Configure it's persistence.xml file as follows: <persistence-unit name="PU"> <provider>org.hibernate.ejb.HibernatePersistence</provider> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties> <property name="hibernate.connection.driver_class" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>