C# Reflection: "Pointer" to a value-type -


short description

i want know if there .net feature letting me manipulate value type obtained reflection. when calling propertyinfo.getvalue(...) on value type property want not copy, original object , manipulate it.

i not allowed use unsafe pointers.

long description

this requirement arose because implementing webservice letting me manipulate unity3d scene graph.

the scene graph might have following structure

  • gameobject 1
    • vector 1.2
  • gameobject 2
    • struct 2.1
    • vector 2.2

a client can query following uri:

get http://.../gameobject2/structproperty/someproperty

this works, as simple traversing hierarchy via reflection, searching property name (e.g. struct or vector) , calling getvalue on corresponding propertyinfo, returning client.

but client can query:

post http://.../gameobject2/vectorproperty/xproperty e.g. 5.4 entity body. x property of vector should set 5.4

what doing @ moment traversing graph forward (like get) till find vector object. doing recursive setvalue until doing setvalue on reference type e.g.

object2.setvalue(vector.setvalue(5.4));

(for simplicity omitting propertyinfo part. assume there)

so must able query arbitrary object hierarchy containing both value types , reference types. there better way doing?

so when calling propertyinfo.getvalue(...) on value type property want not copy, original object , manipulate it.

then need access field, not property. alternatively, need call getter retrieve copy of value, modify copy, , call setter change state of containing object.

that's not true when use reflection - it's true in general. can't like:

foo.position.x = 10; 

where position property type value type. you'll compile-time error. instead, you'd need like:

var position = foo.position; position.x = 10; foo.position = position; 

you can reflection - assuming there is setter, of course.

note when "the original object" here, value type (stored in field of type, i.e. not boxed) there is no object. there's value, field part of object.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -