Jump to content
  • Advertisement
Sign in to follow this  
Yoav

[.net] Using C# reflection

This topic is 3188 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

Hello, I trying to change a data member in a class using reflection. I have an object inside the class which I want to replace with an object of the same kind. due to my system constraints I can't use = or new operators. I am new to reflection and looking for few directions as a starter. Thanks Yoav

Share this post


Link to post
Share on other sites
Advertisement
Sorry,
I meant I ahve an Instance of the class and want to chane the object member for that instance only.
Thanks again

Share this post


Link to post
Share on other sites
I have found remarkable success with whatever my questions were at http://www.stackoverflow.com. With a little code I might be able to help you out. I am gaining experience rapidly with reflection and delegates in C# with an interface I am developing.

Share this post


Link to post
Share on other sites
I'm not sure I understand your question, but if what you want is change the value of a field, then look at:

FieldInfo.SetValue()

FieldInfo is the descriptor of your field and can be obtained by using:

Type.GetField(fieldName);

The Type describes your class and can be obtained with

myObj.GetType();

If what you want to change is not a field but a property, the use GetProperty() instead than GetField().

Share this post


Link to post
Share on other sites
I am also quite interested in knowing the constraints that force you to seek such a costly solution.

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!