Skip to content

Caching of reflection types - best practice? #109

Closed Answered by gfraiteur
tg73 asked this question in Q&A
Discussion options

You must be logged in to vote

You should never use compile-time static fields because, as you mentioned, their value depends on the compilation context, and static fields are shared across several compilations. Aspect classes are even serialized in cross-project scenarios (like cross-project inheritance) so you should design aspects as immutable classes.

You should not spend additional effort to cache calls to TypeFactory.GetType or similar methods because these are already cached. You should just pay attention to call these methods outside of loops.

Now if you are asking about caching System.Reflection objects in the run-time code generated by aspects, then yes, it's probably something you should take care of. Unlike…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by gfraiteur
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants