Jump to content
  • Advertisement
Sign in to follow this  
MrSparkle27

[MDX] Reflecting the DirectX.Vector3 type

This topic is 4024 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
@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?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!