I'd like to return the properties of a series of DbSet objects I have saved to a class using reflection, but in order to access this data in a single method I'd need to pass a variable as an accessor to return the properties of that object.
Currently I've managed to return the properties of all of the DbSet objects, but the code looks very DRY.
public List<List<string>> GetProperties()
{
DbContext client = new DbContext();
List<List<string>> allProperties = new List<List<string>>();
List<string> DbSetAProperties =
client.DbSetA.GetType().GetProperties().Select(e => e.Name).ToList();
List<string> DbSetBProperties =
client.DbSetB.GetType().GetProperties().Select(e => e.Name).ToList();
allProperties.Add(DbSetA);
allProperties.Add(DbSetB);
}
My intention is to refactor this so that it accepts a DbSet name as an argument and returns a single list of properties, rather than a list of all properties.
Aucun commentaire:
Enregistrer un commentaire