I have a custom TypeLevelAspect
called PersistentId
which is used on types in several assemblies. I need to store information from these aspects during compile time and use it during runtime - but before the assemblies are loaded . Therefore, I was thinking about storing the information in another aspect - in a different assembly which would definitely be loaded.
Is it possible to somehow transfer data during CompileTimeInitialize
of one aspect to a single instance of another aspect so that it can be stored and retrieved in RuntimeInitialize
of the second aspect?
EDIT: Sharing data between aspects does seem to work (see the answer below) but only within a single assembly. Is there a mechanism to share it also between different assemblies?
The usual approach to share data between aspects using PostSharp Framework is (assuming you want to share a class MyData
:
MyData
class is serializable.MyData
somewhere.MyData
, expose an instance field of this type, and initialize it to the static instance. At compile-time, PostSharp will serialize MyData
in the aspect graph. Because this is a graph, a single instance of MyData
will be shared among all aspect instances.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.