code-generation

Executing C# or VB.NET code at Runtime

回眸只為那壹抹淺笑 提交于 2019-12-05 02:28:35
问题 Been spending some time on Codility.com recently and it crossed my mind; how do they execute the code you have created (Specifically pertaining to C# and VB.NET) ? What I am basically wondering is how would I take a textbox on a form type some code in it and then run that code? Is this possible without 3rd party tools? Also how would you prevent security violations specifically pertaining to a web based implementation of such a program? 回答1: Have a look at http://msdn.microsoft.com/en-us

CodeDom and collection initializers

六月ゝ 毕业季﹏ 提交于 2019-12-05 02:27:58
问题 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" }, ... }; 回答1: 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 回答2: You

T4 append output to existing file

谁说我不能喝 提交于 2019-12-05 01:16:25
Is it possible to make a T4 template output to be merged with an existing file? For example, if a T4 template generates localization resource XML files, is it possible to merge them in some existing resource file? You can get access to the underlying string builder the the T4 uses thought the GenerationEnvironment property. So by adding something like the following to your T4 you should be able to get a workable solution; <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".txt" #> <#@ Import Namespace="System.IO" #> Line #<#= rand.Next(0, 100).ToString() #>

What is model driven development good for?

旧街凉风 提交于 2019-12-05 01:05:54
问题 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? 回答1: 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

Change output directory of generated code in gradle

亡梦爱人 提交于 2019-12-05 01:05:27
Project contains annotation processor which generates java code during compilation. By default, gradle outputs generated source files into build/classes directory. That causes some problems with discovery of newly generated source files by IntelliJ. Is there any straightforward way of configuring gradle to output source files into another directory? For example $buildDir/gen/main/java or $buildDir/build/generated/main/java ? There is an option for java compiler which allows to customize output directory for generated java sources ( documentation ). -s dir Specify the directory where to place

how to generate constructors in eclipse

六月ゝ 毕业季﹏ 提交于 2019-12-05 00:58:33
I have a class A and B.M extends A. Now I want a create a constructor of B using code generation option of eclipse which accepts parameters and set values of all fields of B (I mean it should also set fields inherited from A). Is there any shortcut to generate such code in eclipse? Right click in the editor and click "Source -> Generate Constructor using Fields". You can select the super constructor to use and also select instance variables to add to the constructor. Eclipse (3.5) has no built in option for that particular case, but I would anyway suggest that you have a separate constructor

How to use a custom strategy with the jOOQ code-generator and Maven?

笑着哭i 提交于 2019-12-05 00:02:49
With jOOQ , I may want to combine using the jOOQ code generator with Maven and a custom generator strategy . It looks as though this can be done as such (leaving out irrelevant parts): <plugin> <groupId>org.jooq</groupId> <artifactId>jooq-codegen-maven</artifactId> <version>2.2.2</version> <!-- The plugin should hook into the generate goal --> <executions> <execution> <goals> <goal>generate</goal> </goals> </execution> </executions> <configuration> <generator> <name>org.jooq.util.DefaultGenerator</name> <!-- But the custom strategy is not yet compiled --> <strategy> <name>com.example

Generate random codes in Client-Side of GWT

喜欢而已 提交于 2019-12-04 23:23:34
问题 I have created a java gwt application in which I want to verify user's email address from client side, is there any way to generate random 5 character code on client side? Any sort of help will be appreciated. 回答1: Why don't you test with Java Math.random() .You can simply get by it. Here is useful formula for generating random numbers (int)(Math.random() * (max - min) + min) So , you can generate 5 random numbers as like... String randomCodes = String.valueOf((int) (Math.random() * (99999 -

XmlCodeExporter and nullable types

穿精又带淫゛_ 提交于 2019-12-04 23:22:39
System.Xml.Serialization.XmlCodeExporter generates code (in code CodeDom form) from an XSD schema. But it does it with some quirks. For example an optional element: <xs:element name="Something" type="xs:decimal" minOccurs="0" maxOccurs="1"/> I would expect this to generate a corresponding code member of type Nullable<decimal> , but it actually creates a member of type decimal , and then a separate SomethingSpecified field which should be toggled separately to indicate a null value. This is probably because the library is from before the introduction of nullable types, but it leads to really

Can I generate an async method dynamically using System.Linq.Expressions?

那年仲夏 提交于 2019-12-04 22:39:51
I know the compiler can't convert an async lambda expression to an expression tree, but is it possible to generate the expression tree manually ? var expr = Expression.Lambda<Func<Task>>( // how do I use 'await' in the body here? ); var func = expr.Compile(); I can't find any method related to async or await in the Expression class, but perhaps there's another way? await involves significant compiler re-writing; the generated IL is quite dissimilar to the original C#, with variable hoisting (onto a class) and branching, tasks, continuations, etc. It certainly isn't something that can be