I can do an eval(\"something()\");
to execute the code dynamically in JavaScript. Is there a way for me to do the same thing in C#?
An example of what I
You might check the Heleonix.Reflection library. It provides methods to get/set/invoke members dynamically, including nested members, or if a member is clearly defined, you can create a getter/setter (lambda compiled into a delegate) which is faster than reflection:
var success = Reflector.Set(instance, null, $"Property{i}", value);
Or if number of properties is not endless, you can generate setters and chache them (setters are faster since they are compiled delegates):
var setter = Reflector.CreateSetter
Setters can be of type Action
but instances can be different at runtime, so you can create lists of setters.