By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,965 Members | 1,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,965 IT Pros & Developers. It's quick & easy.

MakeTypedReference :error=TypedReferences cannot be redefined as primitives.

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
"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.