mardi 20 août 2019

Net Core: Place StartsWith into Expression Method Info to not Receive Ambiguity Error

How do I place this method into an expression builder safely? First parameter is string, second parameter is enum.System.StringComparison. The second enum parameter is giving error.

return persons.Where(p => p.Name.StartsWith(filterModel.Term, StringComparison.InvariantCultureIgnoreCase))  

Eventually want to place this into a method builder, and its giving error below.

MethodInfo startsWith = typeof(string).GetMethod("StartsWith", new[] { typeof(string), typeof(enum(string)) });

public class Person
{
    public String Name { get; set; }
    public DateTime DOB { get; set; }
    public String Email { get; set; }
}

Resources:

C# Reflection typeof(string).GetMethod("Equals) Ambiguous match on netcoreapp2.2

GetProperty reflection results in "Ambiguous match found" on new property





Aucun commentaire:

Enregistrer un commentaire