I have a decent sized set of data that needs to be stored in an active record. In order to prepopulate the form fields on the page, I have already written the following code:
Device device = new Device(DeviceID); // device is simply the active record
txtDeviceName.Text = device.Name;
txtNotes.Text = device.Notes;
txtHostName.Text = device.Hostname;
txtAssetTag.Text = device.AssetTag;
txtSerialNumber.Text = device.SerialNumber;
// snip... the list goes on!
Is there some sort of the method (built-in functionality, macro, etc.) that I could use to swap each side of the expression such that the data is saved into the active record as opposed to read from it in order to perform a database insert? For example, after highlighting the above code and running the macro, it would become:
device.DeviceName = txtDeviceName.Text;
device.Notes = txtNotes.Text;
device.Hostname = txtHostName.Text;
device.AssetTag = txtAssetTag.Text;
device.SerialNumber = txtSerialNumber.Text;
// snip again...
Since the number of columns in the database that this active record encapsulates is rather large, it seems like most of this typing could be avoided with a simple automated process.
Obviously this wouldn't work 100% because sometimes there would have to be type conversions (e.g. int
to string
) but for the most part I think this would save a lot of time.