• Advertisement
Sign in to follow this  

[.net] Using C# reflection

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