c# - Return custom dynamic type -


the dto classes we're returning dapper decorated attributes provide metadata each property (used ui), e.g:

public class person {     [metadata("first name")]     public string firstname { get; set; }     [metadata("last name")]     public string lastname { get; set; } } 

in cases objects returned table may vary customer customer. have set of "common" fields , set of custom ones e.g. person.foo.

to facilitate intend use dynamic object (derived system.dynamic.dynamicobject).

public class dynamicperson : dynamicdto {     [metadata("first name")]     public string firstname { get; set; }     [metadata("last name")]     public string lastname { get; set; } } 

the idea can reflect on instance properties metadata , use mechanism obtain dynamic property metadata.

when run following test:

var query = "select 'ben' firstname, 'foster' lastname, 25 age"; var people = cn.query<dynamicperson>(query); 

only instance properties set (firstname , lastname). can make dapper set dynamic properties don't existing on instance?


Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

c# - Unity IoC Lifetime per HttpRequest for UserStore -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -