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