-2

I know that reflection can get the fields from a type. But I would like to get and set the fields of an instance of a object dynamicly. Is this possible?

4
  • If you know about reflection, can you please clarify exactly what it is you're asking about here? Commented Mar 26, 2019 at 11:25
  • @Jesse why do you keep mentioning a Web Software architecture? The question has nothing to do with Web. Also, even a 10 year old answer holds value, as long as it is still relevant (which it is) and answers the question (which it does). And, that's a lie, the most recent C# version released is C# 7.0 alongside Visual Studio 2017, C# 8.0 is not even close to release Commented Mar 26, 2019 at 11:53
  • @Jesse if the answer is still the best answer to the question, why re-invent the wheel? Commented Mar 26, 2019 at 12:39
  • @Jesse you can try over on the meta site, and I wish you all the best ;) Commented Mar 26, 2019 at 13:17

1 Answer 1

1

GetField you want to set field from the instance then use SetValue method.

 obj1.GetType().GetField(name).SetValue(obj1,value);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.