I think I'm very close to have this figured out, but I haven't made progress for some time now and don't really have a choice but to ask around.
I have a GraphicsSettings class with a large set of graphics properties. These properties have a placeholder value with the property's name, which I use for a comparison loop.
The comparison loop is a function inside the class, and is between an array of the graphics properties and a Stringreader going over lines in an external text file.
When the loop finds a match between the value of a graphics property and a part of what is in a line, I want to set the entire value of the line into the graphics property.
Here's the problem though, I do not know how to call the property setter from within the class without specifically typing out it's name, which I cannot do since its a loop.
I've tried using:
this.GetType().GetProperty(key).SetValue(this,line, null);
Where "key" is the property name and "line" is the line value. From what I understand, this should work just fine when calling a class object from the outside to set a value, but it seems to be utterly against calling a class from the inside using this method.
All I get is a
TargetInvocationException was unhandled error. Not too surprising, but I dont know how to get around this.
So I guess it comes down to this: How do I access a property through the use of a string, from inside the same class where the property resides?
TargetInvocationExceptioncan be quite deceptive. Be sure to check out all nested InnerExceptions, because most likely they will give you a better idea of the true, underlying cause.keyis in fact the property name (case sensitive) and that line doesn't break any type boundaries (e.g. settingnullto anint).