Sign in to follow this  
Yoav

[.net] Using C# reflection

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this