I'm trying to work out if the following is possible, I've done lots of googling and I'm a bit confused. I'm pretty sure I can work out the class reflection on the object class and updating the database isn't a problem once I have the loop, but I can't work out if this is possible at all.
If I was doing this with a fixed class object it'd be easy I'd just do:
public void updateDB(obj_Users myObject)
But as I have a lot of class objects that will take a long time, so trying to make it more dynamic.
Here is a sample of a class I want to pass through (but could be anything following the same format):
public class obj_Users
{
public Int32 UserID { get; set; }
public String UserName { get; set; }
public String FirstName { get; set; }
public String Surname { get; set; }
public String Email { get; set; }
public Int32 UserRole { get; set; }
public Int32 UserCompanyID { get; set; }
public String UserPassword { get; set; }
public Boolean IsAdmin { get; set; }
public String SessionKey { get; set; }
}
Here is some pseudocode of what I'm trying to achieve to explain:
public void updateDB(AnyClassObject obj_Users)
{
// Loop through obj_Users and grab the properties
// DB update call
}
obj_Users.GetType().GetProperties(), is there anything in particular you are stuck with?object, then you can pass in an instance of any class or struct.