I have a database object (a row), that has lots of properties (columns) that map to form fields (asp:textbox, asp:dropdownlist etc). I would like to transform this
Assuming that data is some object and that you want to put its public properties into a Dictionary then you could try:
Original - here for historical reasons (2012):
Dictionary FD = (from x in data.GetType().GetProperties() select x)
.ToDictionary (x => x.Name, x => (x.GetGetMethod().Invoke (data, null) == null ? "" : x.GetGetMethod().Invoke (data, null).ToString()));
Updated (2017):
Dictionary dictionary = data.GetType().GetProperties()
.ToDictionary(x => x.Name, x => x.GetValue(data)?.ToString() ?? "");