468,505 Members | 1,768 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,505 developers. It's quick & easy.

MakeTypedReference :error=TypedReferences cannot be redefined as primitives.

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 =^.^=
Nov 2 '07 #1
1 1989
"colin" <co*********@ntworld.NOSPAM.comwrote in message
news:gq********************@newsfe7-gui.ntli.net...
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 =^.^=
Nov 2 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Sorisio, Chris | last post: by
reply views Thread by Matthew Louden | last post: by
1 post views Thread by Vycka | last post: by
2 posts views Thread by sam.barker0 | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.