Is there a way to put attributes into properties of an anonymous type?

Is there a way to place property attributes in an anonymous type? Or an anonymous type? If not, when do you create it, perhaps after reflection?

As a potential use case, let me borrow from Dapper :

When providing parameters to execute a request in Dapper, you specify parameters of an anonymous type:

connection.Query<Foo>(sql, new { Id = guid, Condition = true });

Let's say I needed to tell something about the match, for example, we can store Boolean as text T/ F(terrible, but unfortunately true for real experience), so I want to add to this attribute Conditionto tell Dapper how to match it (again, this is a slightly coercive example). Is it possible?

+5
source share
1 answer

No, you cannot do this at the time of announcement, or after reflection.

Closest you could use an existing anonymous type as the basis for a new type created using CodeDom or, possibly, Mono Cecil .

I suspect you better just write the code manually yourself.

+6
source

All Articles