How do I define a property to read an attribute from, without instantionating an object?

前端 未结 5 1423
名媛妹妹
名媛妹妹 2021-01-23 10:00

Suppose I have:

class Person
{
[ColumnAttribute(\"ID\"]
    public int Id;
[ColumnAttribute(\"Name\"]
public string Name;
[ColumnAttribute(\"DateOfBirth\"]
    p         


        
5条回答
  •  梦毁少年i
    2021-01-23 11:02

    In addition to Pete M's answer you could pass the Func used in IEnumerable.OrderBy into your method, and order within your method

    public IEnumerable GetAllByAge(int age, Func orderBy)
    {
       var people = ... (get your collection of 'age' aged people here)
       return people.OrderBy(orderBy);
    }
    

    Usage would then be Dal.Person.GetAllByAge(25,p => p.BirthDate)

提交回复
热议问题