Peter Duniho said:
Different thread, different context. You can't assume that everyone has
read every thread.
yes I quite agree, I initialy meant to follow
on from the other thread but was a very diferent aspect
of the same problem. sorry for not being so clear first time.
I gues I assumed if someone saw __refvalue they would
realise I was doing something a bit more complicated.
Well, my first thought is: you're using Reflection. You deserve to have
some headaches.
eek ! well its better than the mess you can get in with pointers in c
when things start to get out off step.
That said, given how Reflection works I'm not sure what alternative you
expected. It probably won't help answer your question, but would you mind
posting an example of code that you'd like to compile and run, but which
doesn't work? That would probably at least help me (if not someone else)
understand the question better.
One thing I'm also not really clear on is, in the code you posted, why are
you using a "ref" parameter anyway? You never change the value of
"destObj", so I'm not understanding why you made it "ref".
thanks, the code I posted now does work,
but obviously there a bit more to it than that,
theres a whole load of code that actually does putting
in the variables, such as strings, bools and compact longs,
but like I said I end up doing a copy for structures.
I gues its too much to hope for to avoid that.
other things like Int32, and some packed structurs can be
binarily copied.
theres custom attributes wich control the
whole process. some fields need to read themsevles via an interface
other fields need to clean up before the next field is read etc.
and the custom atributes can be put for the class definition and
for each field as required.
so I cut down the code I posted,
I could post the whole thing I dont mind that but its been choped
about so much youd probably be falling over things wich arnt
bothering me (much)
i think its probably too much for some news servers to cope with
the whole lot
the only reason I need a ref at all is some fields
are structures wich anrnt suitable to be copiied with
with PtrToStructure, so i need to go through each field by calling
recursivly,
so I need to pass it as a ref to fill in the fields
without a ref it just fills in the fields of a copy wich then gets thrown
away.
public void GetFields2(ref object destObj,Type type )
{
<<<whole load of other stuff to see if theres attributes >>>
<<<to control the reading of the class >>>
if(type==typeof(string))
{ /// string is stored almost the same but not quite.
destObj=file.ReadString(file.readByte());
file.seek(1,current);
return;
}
else if ....
<<do other field types as well as packed structures>>>
System.Reflection.FieldInfo[] fields = type.GetFields();
object fieldObj;
foreach (System.Reflection.FieldInfo field in fields)
{
<<< more attribute to controll reading of each field>>>
<<< such as skipping fields, special reading functions >>>
<<< cleaning up after fields etc >>>
if (field.IsStructure)
fieldObj = field.GetValue(destObj);
else
fieldObj = null;
///recursivly do all fields and sub fields
GetFields2(ref fieldObj,field.FieldType);
field.SetValue(destObj, fieldObj);
}
}
Colin =^.^=