In any case, I can change this method so as not to need an object, but just pass the parameter expression:
protected void FillInTextFor<T>(T obj, Expression<Func<T, object>> property) { var memberExpression = (MemberExpression)property.Body; var propertyInfo = (PropertyInfo)memberExpression.Member;
Called as
var personToCreate = new PersonBuilder().RandomFirstName().Build(); FillInTextFor(personToCreate, a => a.FirstName);
I would just say FillInTextFor(_ => personToCreate.FirstName); or something similar
We are trying to make helper methods for Selenium tests. I want to pass an object and select a property, and it will automatically use the property name as the identifier of the element, and the text as the value for the string.
source share