I have a number (maybe a lot) of classes that are simple like so
public class ResultA
{
public DateTime Date { get; set; }
public int Year { get; set; }
public int Month { get; set; }
public int Day { get; set; }
}
public class ResultB
{
public string Number { get; set; }
public int Count { get; set; }
public string Update { get; set; }
public int Jewels{ get; set; }
}
There is no common interface, but they don't have methods simply properties.
I would like to be able to convert any type like this into a KeyValuePair<string,string>
with the property name and the value if it is set.
Is there anyway of doing this horrible thing!?
Use reflection like this:
Output:
You can also use a extension method:
Usage: