code-generation

Associate attribute with code generated property in .net

自闭症网瘾萝莉.ら 提交于 2019-11-30 01:55:42
I wish to set an attribute on a public property in .NET, however I do not have access to the explicit property itself, as this has been code generated in another file. I have this field: public virtual string Name { get; set; } I wish to set this: [ValidateNonEmpty("Name is required", ExecutionOrder = 1)] public virtual string Name { get; set; } My class is marked as partial, but you cannot have partial properties. I thought I was on to something with the MetadataType class which is a new feature of Dynamic Data and DataAnnotations, but alas I feel it can only be used with Dynamic Data, is

C# code generator [closed]

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 01:40:29
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . Can someone recommend a simple c# code generator. I just looking something with methods like: GenClass = CreateNewClass(AccessModifier

How are exceptions caught and dealt with at the low (assembly) level?

我只是一个虾纸丫 提交于 2019-11-30 01:31:51
问题 I have this code - try { doSomething(); } catch (Exception e) { e.printStackTrace(); } How will this actually be implemented by the compiler. Where is the check for the exception actually put in the assembly code generated? Update I know that how the above code is translated to bytecode . The bytecode only translates the try-catch to corresponding try-handler blocks. I am interested in how it will be translated to assembly/and or handled by the jvm. 回答1: The cost of try-catch block Roughly

How to output namespace in T4 templates?

邮差的信 提交于 2019-11-30 01:27:01
I have a T4 template for a class set up with TextTemplatingFileGenerator Custom Tool in Visual Studio: <#@ template language="C#v3.5" hostspecific="True" debug="True" #> <# var className = System.IO.Path.GetFileNameWithoutExtension(Host.TemplateFile); var namespaceName = "MyNamespace"; #> namespace <#= namespaceName #> { public static class <#= className #> { // some generated code } } How can I get the value of the "Custom Tool Namespace" property in Visual Studio, so I don't have to hardcode the namespace? I would even be happy with the default namespace for the C# project. If you're using

(Kotlin) Backend Internal error: Exception during code generation

試著忘記壹切 提交于 2019-11-30 01:18:17
问题 I am creating a very thorough converter for Android with Kotlin, using the latest Android Studio Canary build and latest Kotlin. I am suddenly getting a compiling error, even thought Android Studio doesn't see any bug in the code, it is complaining about a backend error, so I think my project is good but the Android Studio has a bug?? Please help confirm, this has been a lot of work.... It is complaining about my class MassCalc, which is 6500 lines long, because of many cases for conversion,

define additional source directory in maven

*爱你&永不变心* 提交于 2019-11-30 01:15:09
问题 I generate Java sources from a wsdl file. These sources are not under version control (but the wsdl is). We use the cxf-codegen-plugin in maven and the generated classes are generated in <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot> . This works all fine in maven. I have to define this directory as addition source directory in Intelij Idea. ( target is normaly excluded). But every time I re-import the maven project into InteliJ Idea (due to pom changes), I have to manually

Is there an Emacs Lisp library for generating HTML?

人走茶凉 提交于 2019-11-30 00:22:44
I'm looking for a solution that allows me to write native Emacs Lisp code and at compile time turns it into HTML, like Franz's htmlgen : (html ((:div class "post") (:h1 "Title") (:p "Hello, World!"))) Of course I can write my own macros , but I'm interested if there are any projects around this problem. Trey Jackson As you found out , xmlgen generates XML from a list structure. What I did find disappointing with the ``xmlgen` package that the format it supports is not quite the inverse of Emacs' xml parser . I did add this to my copy of xmlgen: ;; this creates a routine to be the inverse of

Using Roslyn to parse/transform/generate code: am I aiming too high, or too low?

情到浓时终转凉″ 提交于 2019-11-30 00:09:33
(What I'm trying to do is work around the Application.Settings/MVVM problem by generating an interface and wrapper class from the vs-generated settings file.) What I'd like to do is: Parse a class declaration from file Generate an interface declaration based on just the (non static) properties of the class Generate a wrapper class which implements this interface, takes an instance of the original class in the constructor, and 'pipes' all the properties through to the instance. Generate another class which implements the interface directly. My question is two-fold: Am I barking up the wrong

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

狂风中的少年 提交于 2019-11-29 23:06:28
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 JSONArrays. This is a demo: You can download it from : "Preferences" -> "Plugins" -> "Browse Repositories" -> "RoboPOJOGenerator" And how to use: And you paste you json to popup and choose parser type: And click generate, it will gen class from json for you! I hope it can help you to save many time! 来源: https://stackoverflow.com/questions/47707564/how-to-use

Free NHibernate helper tools?

£可爱£侵袭症+ 提交于 2019-11-29 21:57:29
Are there any free tools to help simplify working with an NHibernate project in .NET 3.5? Primarily, I'm looking for some kind of code and config file generator to automate some of the more tedious parts of working with NHibernate. Fluent-NHibernate presents an alternative way of writing your mapping, that for example is more refactor friendly than the standard XML approach. Example: public CustomerMap : ClassMap<Customer> { public CustomerMap() { Id(x => x.ID); Map(x => x.Name); Map(x => x.Credit); HasMany<Product>(x => x.Products) .AsBag(); Component<Address>(x => x.Address, m => { m.Map(x =