[MDX] Reflecting the DirectX.Vector3 type

Started by
2 comments, last by MrSparkle27 16 years, 9 months ago
Hi, I have troubles to show a Vector3 property of an object in the PropertyGrid. Trying to reflect the Vector3 type also fails: typeof(Vector3).typeof(Vector3).GetProperty("X") returns null which means that there is no property called "X". GetField("X") returns a field called "X". Looking into the disassambly of the Vector3 struct using the Reflector, it looks like this: ------------------------ private float <backing_store>X; public float X { get { return this.<backing_store>X; } set { this.<backing_store>X = value; } } ------------------------ As you can see, there is a private field and a public property, both called "X". But that's different to the above result the .NET reflection methods returned. What makes the declaration different from other such structures is the "<backing_store>" statement. Does anybody know what this means? Thank you very much, Christian
Advertisement
The <backing_store> probably comes from the fact that the Vector3 class was written in C++/CLI like:
value class Vector3{  public:    property float X;    property float Y;    property float Z;  //...};

C++/CLI supports this particular "shortcut" to property generation that implicitly creates members named <backing_store>X, <backing_store>Y, et cetera (so that the fields have different names than the properties). In other words its just fancy name-mangling going on.

The MDX math classes lack the appropriate type descriptors and other metadata attributes to make them fully useful in, for example, PropertyGrids. Since they are also sealed value classes, you cannot subclass them. Best option is to wrap them in your own class that provides the support. Alternatively, I will probably add the appropriate metadata to the math objects in SlimDX sometime soon, so you could migrate to that.
Yes, you should debug it and gather the PropertyInfo, MemberInfo, etc. And look to see what's available. You can reflect it. I have a property editor setup that does the same thing. I wrote my own from scratch though, so it could have custom everything.

-Devin
@jpetrie

I never learned C++, so thank you for your explanation. But still, I cannot explain why the property is always reflected as a field with .NET.


@devronious

I tried to write my own TypeConverter and PropertyDescriptor classes to display the Vector3 in a PropertyGrid but it causes strange behaviour wenn setting the values to the reflected XYZ-fields. How could I extend the PropertyGrid to handle Vector3 values?

This topic is closed to new replies.

Advertisement