MakeTypedReference :error=TypedReferences cannot be redefined as primitives.

C

colin

Hi,
I have this code wich fills in data fields from a file,
recursivley down through any structures/classes
the difficulty is when I come acros a field wich is a structure,
wich can not be read as a binary blit.

I need to be able to pass this as a reference to
a function to carry on the recursion through each field...
I have tried to use TypeReferences but I get this error and
I cant find anything much about it.

public void GetFields(ref object destObj)
{
Type type = destObj.GetType();
System.Reflection.FieldInfo[] fields = type.GetFields();
foreach (System.Reflection.FieldInfo field in fields)
{
if(<<< tests to make sure we realy need to do this for this field{
System.Reflection.FieldInfo[] field_s=new FieldInfo[1]{field};
TypedReference
destRef=TypedReference.MakeTypedReference(destObj,field_s);
<<<< gives exception "TypedReferences cannot be redefined as
primitives." >>>>
}
}
}

can any one shed any light or offer any other way of doing it ?
I cant find any info or make sense of it.

can my sub function return a structure that it creates somehow
with only knowing at runtime ?

I manage to do that if the structure is blitable by using PtrToStructure
as sugested by Mattius, and the rest of it works fine if I avoid structures
that
cant be blitted.

the data in the files is an existing format and is a mixture of
direct binary values and complicated conversions.

thanks
Colin =^.^=
 
C

colin

colin said:
Hi,
I have this code wich fills in data fields from a file,
recursivley down through any structures/classes
the difficulty is when I come acros a field wich is a structure,
wich can not be read as a binary blit.

I need to be able to pass this as a reference to
a function to carry on the recursion through each field...
I have tried to use TypeReferences but I get this error and
I cant find anything much about it.

public void GetFields(ref object destObj)
{
Type type = destObj.GetType();
System.Reflection.FieldInfo[] fields = type.GetFields();
foreach (System.Reflection.FieldInfo field in fields)
{
if(<<< tests to make sure we realy need to do this for this field{
System.Reflection.FieldInfo[] field_s=new FieldInfo[1]{field};
TypedReference
destRef=TypedReference.MakeTypedReference(destObj,field_s);
<<<< gives exception "TypedReferences cannot be redefined as
primitives." >>>>
}
}
}

can any one shed any light or offer any other way of doing it ?
I cant find any info or make sense of it.

can my sub function return a structure that it creates somehow
with only knowing at runtime ?

I manage to do that if the structure is blitable by using PtrToStructure
as sugested by Mattius, and the rest of it works fine if I avoid
structures that
cant be blitted.

the data in the files is an existing format and is a mixture of
direct binary values and complicated conversions.

seems it doesnt like it when the field is a primitive value type.
however I can avoid this case.
dont know why this should be so ?

Colin =^.^=
 
Top