I have an object called User, with properties like Username, Age, Password email, etc.
I initialize this object in ado.net code, for example:
private User LoadUser(SqlDataReader reader)
{
User user = new User();
user.ID = (int)reader["userID"];
}
Now let's say that I create a new object that is inherited from the user, for example:
public class UserProfile : User
{
public string Url {get;set;}
}
Now I need to create a method that will load userprofile, so currently I'm doing:
public UserProfile LoadUserProfile(SqlDataReader reader)
{
UserProfile profile = new UserProfile();
profile.ID = (int)reader["userID"];
profile.Url = (string) reader["url"];
}
Is there another approach to OOP, so I don't need to reflect my code in LoadUserProfile () from LoadUser ()?
I would like to do this:
UserProfile profile = new UserProfile();
profile = LoadUser(reader);
// and then init my profile related properties
Is it possible to do something like this?
source
share