Is it possible, and not to stupid, to create a methods that returns only a select few properties from a large object based on the input?
I have a large object that I can retrieve. The problem is that it takes quite awhile to fill/generate the entire object. I would like a single method that can fill parts of that object based on what I send in. Say that there are 100 properties in the object. In several cases i only need 1 of the properties of the object to do some checking, or a select few properties. I can make separate methods to get that property only, but this quickly generates alot of very similar methods and it will be a pain to work with and maintain.
The properties in the object are a mix of simple and complex. Some of them are just boolean and strings while others make call to a DB to resolve custom objects from a Id on the object. For example retrieves a customer object based on the customer Id.
I want to do something like this:
public MyObject FillSelectProperties(guid Id, params string[] properties)
{
foreach(property in properties
FillProperty(property);
}
Or something like that. Maybe use reflection? Or some other way that is more efficient.
Example:
var mo = FillSelectProperties(id, "Prop4", "Prop17", "Prop18");
if(mo.Prop4 == true)
//do something with mo.Prop17 and moProp18
I dont know if this is only wishful thinking that this is solvable without generating alot of specific methods.