I haven't worked with expressions that much, I am trying to reference an Expression property by string name but I cam getting this error:
c# The member expression must specify a property or method that is public and that belongs to the type Soly.Models.Profile (Parameter 'expression')
public class ProfileFilterType : FilterInputType<Profile> {
protected override void Configure(
IFilterInputTypeDescriptor<Profile> descriptor) {
descriptor.BindFieldsExplicitly();
descriptor.Field(f => Build<IFilterInputTypeDescriptor<Profile>, string>("firstName"));
}
public static Expression<Func<TClass, TProperty>> Build<TClass, TProperty>(string fieldName) {
var param = Expression.Parameter(typeof(TClass));
var field = Expression.PropertyOrField(param, fieldName);
return Expression.Lambda<Func<TClass, TProperty>>(field, param);
}
}
descriptor.field signature:
IFilterFieldDescriptor Field<TField>(Expression<Func<T, TField>> propertyOrMember);
I am trying to iterate over the Profile properties with reflection and add a field descriptor for each in HotChocolate GraphQL.