开发者

Using autogenerated code without pregenerating?

Is it possible to use an autogenerated class in the same run as it is being generated? I am trying to achieve something which works as a factory but for autogenerated classes. My scenario is like this:

I have files which specify what some resulting files can contain. These result files should then be used to calculate statistics or something other than that. Now I would like to modify the data when these are read but since the software does not know what parts are written to file, it does not know how to save the data in the files internally. I have a reader and writer (made by a friend and which are VERY genreric and too cumbersome to use). I figured that I could use the definitions to autogenerate classes/structs.

for instance: classes which can be written are "A", "B" and "C". Say that "A" and "B" have two and three children respectivel开发者_如何学Cy. Lets call these A0, A1, B0, B1,B2.

Now internally in the software, I would like to write:

A aObject = new A0();
aObject.variable1 = 2;
aObject.variable2 = "something";

B bObject = new B1();
bObject.SomeVariable = 42;
bObject.SomeOtherVariable = "someValue";

what the variables are called and what type the data represents is written in a specification file. In xml for instance, it would be something like:

<A0>
<Variable>
   <Name>variable1</Name>
   <type>int</type>
</Variable>
<Variable>
   <Name>variable2 </Name>
   <type>string</type>
</Variable>
</A0>

(same with A1, B0, B1, B2 and so on)

Now, I would like to read a result file, realize I would have to autogenerate A0, generate it, modify the data (with the class/struct A0 which was just created) and then write to file again.

My solution for this is to pregenerate all possible classes/structs beforehand and include them. Problem with this is that the versions of A, B and C are or will be changing.

All help is appreciated :)


The rest of your question did not make all that much sense to me to be honest, but to answer your very first question: yes you can do that. Have a look here for instance.

Regards Gert-Jan

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜