I am looking for optimization of a template that I use for an application with dynamic forms.
I have a repository class using a method:
public Entity Find(string objectId, List<string> includedProperties);
Returns an Entity object with the fields specified in includeProperties, since creating an entire object for all purposes is unnecessary overhead in this case (some objects have hundreds of properties).
An example domain code using this repository often looks something like this:
var includedProperties = new List<string> { "FirstChildName" , "FirstChildDob", "SecondChildName", "SecondChildDob" }
Then I retrieve the object:
var person = repository.Find("123",includedProperties);
Then I use the properties with the GetProperty(string propertyName) method:
var firstChildDob = person.GetProperty("FirstChildDob").AsDateTime(); ...etc
All this works great and goes well with the dynamic design of the application. However, I find it annoying that I always need to declare the list of "used" properties separately, before receiving the object.
So my question is that through reflection or some other cleverness, can I simplify the creation of "Enabled Properties" by looking at which parameters are passed later in the code using the GetProperty method?
Using the above example, I would like to create a list using such an assistant (or the like):
var includedProperties = HelperObject.GetFieldsUsedInCurrentCodeFile();
This will somehow perceive which string constants were passed to the GetProperty () method, while retaining the need for an explicit declaration. Any suggestions are welcome!