문제

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.

도움이 되었습니까?

해결책

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

dynamic code in c# dynamic code in script

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top