So I have an imported file. Basically, I want to use the headers of this file to know which columns should be placed into which variable value on my class. I’d like to do this comparison via variable attributes in C#, but I’m not really sure how to approach this and set this up.
For example, say one variable in my class is public string Name; and in the imported file, one of the column headers is Name. I’d rather not use reflection to match the variable directly. How can I set an attribute on my class variable, and then use it to match with these local string header variables, and fill the correct one?
Here is an example program that should give you what you need. The
SetOptionmethod is what provides the reflection logic to find the field with the specified option name and set its value.