How can I pass a property as a delegate?

前端 未结 6 1608
深忆病人
深忆病人 2021-02-04 04:03

This is a theoretical question, I\'ve already got a solution to my problem that took me down a different path, but I think the question is still potentially interesting.

6条回答
  •  甜味超标
    2021-02-04 04:59

    No, there's nothing akin to method group conversions for properties. The best you can do is to use a lambda expression to form a Func (for a getter) or an Action (for a setter):

    SetPropertyFromDbValue(value => myClass.Property1 = value,
                                   rdr["field1"]);
    

提交回复
热议问题