.net CodeGenerators?
I need a code generator that:
- is open source
- will run in medium trust
- where templates are either compilable or can be embeded as resource files.
Webforms will not work because of 2 and 3. If I use virtual path provider then it runs only in full trust; if I run them as regular webforms, then I have to provide .ascx files witch is not acceptable.
Update: I want to generate C# or VB.Net code as well as开发者_JAVA技巧 ASP.NET markup, although that should not matter.
Check out the T4 Toolbox.
Take a look at the template support added in .NET 3.5 SP1 for dynamic data for ASP.NET. Microsoft has expanded this in .NET 4 to make templating available in web forms as well as in ASP.NET MVC, and supports both page and field templates. The data annotation support introduced for dynamic data is becoming the foundation for automated validation support. Data annotation is an important aspect for Silverlight and WCF RIA services as well.
These features can reduce the work that needs to be done for code generation, as well as make code generators more powerful.
Starting right now, any viable code generation solution needs to take advantage of these features, regardless of whether the code generator is commercial, open source, or a custom application.
UPDATE:
- System.ComponentModel.DataAnnotations (.NET 3.5)
- System.ComponentModel.DataAnnotations (.NET 4)
- ASP.NET Dynamic Data (look for template design and support)
By the way, if you're looking for runtime code generation, you may be more interested in LINQ expression support; you can use LINQ to build expression trees, and compile those into code at runtime.
T4 that is now present in Visual Studio 2019.
You must add a Text Template file in your project (file-type = TT)
See following link to have more explanations on T4
//learn.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates
精彩评论