[SUGGESTION] Allow Method groups as a substitute for an BsonExpression
Is your feature request related to a problem? Please describe. Code gets bulky and inability to use method groups as a substitute for expressions causes duplicated expressions ie. code fragments.
Describe the solution you'd like Overload that translated my static method group
db.FindOne(MyModel.IsValid)
to a BsonExpression equivalent which is:
db.FindOne(x => x.Foobar && x.Arbitrary > 0)
where MyClass.IsValid in the example is defined as follows.
public class MyModel {
public bool Foobar { get; set; }
public long Arbitrary { get; set; }
public static bool IsValid(MyModel model) => model.Foobar && model.Arbitrary > 0;
}
Describe alternatives you've considered Dublicated code fragments (expressions), but code gets bulky (see above) because dublicated expression cannot be managed from a single place and are spread across the project.
there is 2 way to do that ,
public class MyModel {
public bool Foobar { get; set; }
public long Arbitrary { get; set; }
//property style -- with this , you dont have to pass model to function.
// its already accesing instances fields
public bool IsValid => Foobar && Arbitrary > 0;
//method style -- you have to pass model,
public static bool isValid_method(MyModel item ) { return item.Foobar && item.Arbitrary > 0; }
}
usage:
//property style
var resultsxx = col.Find(x => x.isValid ) ;
//method style
var resultsx2 = col.Find(x => MyModel .isValid_method( x) ) ;
i didnt encount any syntax error ...
Of course. But this is not the same syntactic sugar I am requesting. I specifically request to have method groups be passable without x => MyModel.IsValid(x) when the Find method is expecting a single parametrized method. LINQ normally supports it.