[quoted text, click to view] "Marc Gravell" <marc.gravell@gmail.com> wrote in message
news:039e3152-f908-4de3-a68b-86e07d50038f@s37g2000prg.googlegroups.com...
>I said> a big difference between a primative* type and a value-type
>
> Before things get confusing; can I clarify: I mean that the predefined
> types are a small subset of value-types; i.e. an int (or Int32) *is* a
> value-type; I don't mean that they are mutually exclusive terms.
>
Not sure what your talking about. My write code just recurses over all
types. If its a value type then I write it out to file, else its either a
field or property. (I guess it could be an object which I haven't handled)
The problem, so far at least, is not writing out the structure as I have
done this for some simple ones(and it should work for arbitrary ones I
imagine) but reading them in. I'm having problems reading in arrays because
I must allocate them of the proper type(which I can't because I can't do
dynamic casts ;/).
if (val is Array)
{
object numo = (Int32)0;
ReadValueType(stream, numo);
object[] v = new object[(Int32)numo];
for (int i = 0; i < (Int32)numo; i++)
{
this.DeserializeSub(stream, ref v[i]);
}
val = v;
return true;
}
that is my code right now to handle an array. It doesn't work cause ref v[i]
is an object and not of the proper type(which you can get from the type
parameter from the class(its generic)).
so for example I know what type val contains cause I use the generic type as
a guide which lets me "look" at the types in the class. But because I cannot
cast v[i] dynamically into the proper type I can't do much ;/
for example, in my test code, when I break on the first line(object numo),
val is type object {int[]}
so I need to create v to mimic it and then I would have no issues ;/
I have no clue how to do this though or if its possible.
(basically if val is an array of value types then Deserializesub will get it
and store it in the second parameter.)
Don't know if I'm at a dead end or not though ;/ Would be nice if I could do
somethign like
val.ElementType[] v = new val.ElementType[(Int32)numo]; so that the proper
type can be passed to DeserializeSub. I might be able to modify
DeserializeSub and pass the type in another parameter but it probably will
just end up making a mess.
Jon