[.net] Using C# reflection
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
Sorry,
I meant I ahve an Instance of the class and want to chane the object member for that instance only.
Thanks again
I meant I ahve an Instance of the class and want to chane the object member for that instance only.
Thanks again
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.
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().
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().
I am also quite interested in knowing the constraints that force you to seek such a costly solution.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement