I've got a method which currently takes an IList as a parameter, where UserBO is similar to the following:
public class UserBO {
public string Username { get; set; }
public string Password { get; set; }
public string Pin { get; set; }
}
public class SomeClass {
// An example method giving the basic idea of what I need to do
public void WriteUsers(IList<UserBO> users) {
// Do stuff with users
for (var user in users) {
Console.WriteLine(String.Format(User: {0}: {1}, users.Username, Hash(users.Pin)); // Now needs to optionally be users.Password
}
}
private string Hash(string pin) {
return // Hashed Pin
}
}
This method then uses the Username/Pin pairs to create some XML used by another program (we'll use the above method as an example).
The thing is, now I need to be able to produce the same code except using the Password field instead of the Pin field (there's a good reason for having both fields).
Instead of just creating another method with a similar name, I'd prefer to refactor the code so as to remove the BO specific code from this class entirely, and make it so that the decision about what class/members to use are made not in the method itself but the code calling it.
One option would be to pass an IDictionary and use the Linq ToDictionary method to create a dictionary on the fly in the calling code. This would however lose the ordering of the items (which would be nice but not essential to keep). I could use an IList or something, but that would be more difficult to convert the IList into.
Does anybody have any good suggestions of how to do this?
P.S. If anybody has a better idea of how to title this post, feel free to have a go at it.