Generate multiple attribute?
ATM i cant quiet imagine how this will work. I'm sure it can be done. I notice a pattern use in my attribute where i always use 3 specific attributes together. Take the below as an example
[MyAttr(4, @"开发者_运维技巧a"),
MyAttr(41, "b"),
MyAttr(45, "ab")]
Mine is much more complicated but i would like to define one attribute with more params to generate the data above. How might i do that? Lets say my one attribute will look like this
MyAttr2(4, 41, "a", "b"); //4+41=45, "a"+"b" = "ab"
How might i generate the 3 MyAttr to apply to a class using MyAttr2?
The C# compiler can't convert a single attribute entry into multiple ones in the assembly metadata. However, you could model your attribute in such as way that it exposes additional attribute information as properties (or a collection). However, the child information will not be accessible directly via reflection as independent attributes.
精彩评论