How to create an anonymous object with property names determined dynamically?

后端 未结 3 561
隐瞒了意图╮
隐瞒了意图╮ 2021-02-01 22:56

Given an array of values, I would like to create an anonymous object with properties based on these values. The property names would be simply \"pN\" where N

3条回答
  •  误落风尘
    2021-02-01 23:06

    You cannot dynamically create anonymous objects. But Dapper should work with dynamic object. For creating the dynamic objects in a nice way, you could use Clay. It enables you to write code like

    var person = New.Person();
    person["FirstName"] = "Louis";
    // person.FirstName now returns "Louis"
    

提交回复
热议问题