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.
-
What is the business purpose behind generating new classes dynamically?Yuriy Faktorovich– Yuriy Faktorovich2012-11-04 04:10:22 +00:00Commented Nov 4, 2012 at 4:10
-
It's something I'm working on in my spare time. I have an interest in Artificial IntelligencePaul Matthews– Paul Matthews2012-11-04 04:12:07 +00:00Commented Nov 4, 2012 at 4:12
-
I do too, could you be more specific?Yuriy Faktorovich– Yuriy Faktorovich2012-11-04 04:13:34 +00:00Commented Nov 4, 2012 at 4:13
-
I want to generate a class which simply performs the calculations for a trained feed forward network. Just a black box with inputs and outputs for use in other code. I want to see how fast I can get it to run.Paul Matthews– Paul Matthews2012-11-04 04:20:20 +00:00Commented Nov 4, 2012 at 4:20
-
So you'll need a ton of these to do it genetically? What would it be about using a file that would actually make your process faster?Yuriy Faktorovich– Yuriy Faktorovich2012-11-04 04:22:59 +00:00Commented Nov 4, 2012 at 4:22
|
Show 3 more comments
2 Answers
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.