well I agree the struct v class is confusing thing to get used to.
and the pass by value/ref can be an awkward difference,
its not always the way you want it to be.
it would be expensive to replace all structs with classes,
not only that, the underlying library requires an array of structs for
various things.
especially for vertex data wich is itself a struct containing several
structs,
and has 200,000 instances.
although I dont edit this amount of data with the property editor,
some of the structs are the same type, and this I have little control over,
or would be too inconvenient to have struct and class duplicated.
its hard to use TypedReference however, as you cant use it as a field,
nor can you return it as a function value, you cant even pass it as a ref
nor cast it to anything not even an object or value type.
so you have to use it in the same function, or sub function.
but it does allow you to modify a field of a struct within a struct.
all you need is an array of FieldInfo wich contain the list of nested
members,
and the final fieldinfo, and ofc an object such as a class that holds the
struct.
im not sure how it would work on an aray of structs.
although the class does actually hold a boxed copy of the struct in a
dictionary.
//recursively called
public UData SetField(object value,List<FieldInfosubFfields)
{
....
if(...)
{
List<FieldInfofields = new List<FieldInfo>();
parentUdata = parent.SetField(null, fields);
if (fields.Count 0)
{
fields.Reverse();
TypedReference typedReference =
TypedReference.MakeTypedReference(parentUdata.data , fields.ToArray());
fieldInfo.SetValueDirect(typedReference,value);
return null;
}
fieldInfo.SetValue(parentUdata.data,value);
return null;
}
...
}
Colin =^.^=
"Marc Gravell" <ma**********@gmail.comwrote in message
news:e3**********************************@k13g2000 hse.googlegroups.com...
There is no special reason that primatives aren't affected, except
that they are immutable. That is the key point here:
>the data in the structs does need to be edited though
There is a 99.8% change this is a mistake [according to the department
of invented statistics].
structs in C# (or rather: ValueType in .NET) are not the same as
structs in C++; they are not a "light weight object" or however else
people think of them... the difference is the copy vs reference
semantics. I don't know enough to recommend which... but I firmly
believe that you'll have a much easier time of things if you either a:
switch to classes instead of structs, or b: make the structs
immutable.
Marc