Use CodeDom to generate the file.
Generating a new class dynamically
题
I want to write some code that creates a new class dynamically and store it in a .cs
file.
I was wondering if there is a standard way of doing this other than just creating strings and writing these to a text file? Basically, I have written an object oriented Neural Net and I want it to be able to output a highly optimized hard wired final version of itself to a new class for use in other code.
没有正确的解决方案
其他提示
In addition to writing out the strings into a text file, which is the simplest option that should work for small projects, you could use template engines. Several options are available in .NET:
- Text Template Transformation Toolkit (T4) - A template engine from Microsoft. T4 is used throughout Visual Studio for code generation.
- String Template Engine - A template engine from the designers of ANTLR, a popular parser generator.
不隶属于 StackOverflow