Question

I made a program that achieve a knowledge representation, its good but I thing it could be better if I can create and destroy classes on the fly.

Was it helpful?

Solution

If you are talking about dynamic code generation, here is a link:

dynamic code in c# dynamic code in script

OTHER TIPS

From your description, it sounds like you don't really want to create C# classes at runtime. What you want is some sort of representation of knowledge.

There is no simple answer to this. This is an area of artificial intelligence research. See http://en.wikipedia.org/wiki/Knowledge_representation_and_reasoning for an introduction.

To me it sounds like you want to learn some AI programming and knowledge representation. However this is far different from creating classes at runtime. Wikipedia gives a rather good introduction into the subject, but no code at all.

http://en.wikipedia.org/wiki/Artificial_intelligence

In C# 3.0 it's possible to create anonymous types, though as STW points out, this is not defined at runtime, but compile time.

var myClass = new { A = 5, Id = "MyClass", num = 0.187f};

Console.WriteLine(myClass.Id);

If you're looking to actually create a new class type on the fly, a round-about way is to generate C# class files, compile them into an assembly, and use Reflection to load the classes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top