I am trying to get the properties from a public DTO object that comes from a dynamically instantiated form.
Form equipmentDialog = (Form)Activator.CreateInstance(_lookups.First(d => d.Key == lvwEquipmentCategories.FocusedItem.Text).Dialog, (object)null);
if (equipmentDialog.ShowDialog() == DialogResult.OK)
{
FieldInfo equipmentField = equipmentDialog.GetType().GetFields().First(); //Equipment (DtoEquipment) - there is only one.
List<PropertyInfo> equipmentProperties = equipmentField.GetType().GetProperties().ToList();
}
This doesn't give me the properties I am looking for. It just gives me a bunch of properties like IsPublic, IsPrivate etc.
The result i'm looking for is something like this:
DtoEquipment test = new DtoEquipment();
List<PropertyInfo> testProperties = test.GetType().GetProperties().ToList();
This gives me the properties of my DTO object. But I obviously need to get these properties from the DTO object on the instantiated form.
I have tried casting the FieldInfo as the DTO but that doesn't work.