Let's say I have this class:
public class Test
{
public string Attribute1 { get; set; }
public int Attribute2 { get; set; }
}
and I have object of this class
Test test = new Test();
Now I want to fill this object, but I don't know what attributes are inside. How can I get references for the attributes to fill them? I was thinking about something like this:
List<object> attrs = GetAttributes<Test>(test);
foreach (var attr in attrs)
{
if(attr.GetType() == typeof(string))
{
attr = "filled";
}
else
{
attr = 1;
}
}
Console.WriteLine(test.Attribute1); //print "filled"
Console.WriteLine(test.Attribute2); //print 1