Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm trying to create a generic layer between the frameworks I am using and my application's code and have been blocked by a framework's need to decorate my classes with attributes.

Is there a way to be able to somehow map attributes to other attributes?

Example: Class A is decorated with Attribute B At runtime, map Attribute B to Attribute A Class A is seen as decorated by Attribute A throughout the application's life.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
267 views
Welcome To Ask or Share your Answers For Others

1 Answer

What you are trying to do sounds like bad design. Attributes are not runtime types, they are in fact just type metadata. Even though some attributes allow you to change their parameters at runtime, that will not change which attribute is applied.

You will find solutions on the internet that suggest using Reflection.Emit. Note that this is a slippery slope and will lead to highly unmaintainable code.

My personal suggestion would be to create your own Class B that is decorated with both Attribute A as well as Attribute B, and then use internal logic to bridge whatever it is that you are wanting to bridge.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...